gpt4 book ai didi

iOS Swift Camera Picker 顶部和底部透明

转载 作者:行者123 更新时间:2023-11-28 07:44:19 25 4
gpt4 key购买 nike

是否可以让相机选择器看起来像拍摄视频时的样子。

现在是这样的:

我想让它看起来更像这样:

最佳答案

您不能完全按照您提供的 UIImagePickerController 屏幕截图进行操作,您需要直接使用 AVFoundation并围绕相机预览创建一个 UI。

Apple 讲解基础知识 here网络上有多个教程,例如 one它将向您解释拍摄静态照片或生活照片所需了解的一切。

编辑:您可以使用 UIImagePickerController 设法做到这一点

您需要先将 showsCameraControls 属性设置为 false。然后,您需要使用您自己的控件(例如 UIButton,它是一个 UIView)使用 cameraOverlayView 属性添加您自己的叠加层,然后将 takePictures() 等函数分配给您的按钮以拍照。

imagePicker.sourceType = .camera
imagePicker.showsCameraControls = false
imagePicker.delegate = self
imagePicker.cameraOverlayView = yourOverlayWithWithButtons

相机预览将需要转换为全屏(3 倍比例太大但至少在 iPhone X 上使预览显示为全屏,您当然可以改进它):

imagePicker.cameraViewTransform = CGAffineTransform(scaleX: 3, y: 3)

请注意 cameraOverlayView 属性的 Apple 文档说:

You can access this property only when the source type of the image picker is set to UIImagePickerController.SourceType.camera. Attempting to access this property for other source types results in throwing an invalidArgumentException exception.

查看有关 UIImagePickerController 的 Apple 文档, cameraOverlayViewshowCameraControls .

关于iOS Swift Camera Picker 顶部和底部透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51487184/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com