具有自定义视图的相机
我的应用程序使用相机,我想在相机预览上添加叠加层。例如,我想在使用相机时使用相框,还想添加一个用于相机操作的自定义栏。请帮助我做同样的事情。
My Application uses camera, I would like to add overlay over the camera preview. For example, I want to use a picture frame when I use Camera, also I would like to add a custom bar for camera operations. Kindly help me to do the same.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可能正在尝试使用 UIImagePickerController。但我知道这个可以解决你的问题。您可以使用 AVCamCaptureManager 和 AVCamRecorder 类轻松完成此操作。 Apple 在其开发人员网站上构建了一个演示程序 这里。它被命名为AVCam。简单来说,它的作用是当您单击打开相机时,它会调用负责打开 iPhone 相机并录制视频或捕获音频的类和方法。它调用与 UIImagePickerController 调用的相同的类。这样你的相机就会打开并开始接受输入。
现在,如果您打开该 AVCam 项目的 xib 文件,您将发现一个小的 UIView 对象。该视图负责显示相机的馈送。您可以根据需要调整该视图的大小,相机的输入将显示在该区域中。您还可以根据您的选择在其周围放置框架图像。
当我想要调整相机输入源的大小并拍摄照片时,它对我有用。我希望它也适合你。
You might be trying using UIImagePickerController. But I know this one solution to your problem. You can do it easily using AVCamCaptureManager and AVCamRecorder classes. Apple has a demo program build on its developer site here. It is named AVCam. In simple words what it does is when you click to open the camera, it calls the classes and methods which are responsible for opening the iPhone's camera and record video or capture audio. It calls the same classes which are called by UIImagePickerController. So your camera will open and start taking input.
Now, if you open the xib file of that AVCam project, you'll find a small UIView object. This view is responsible for displaying the camera's feed. You can resize that view as per the size you want and the camera's input will be displayed in that much area. You can also put the frame image around it as per your choice.
It worked for me when I wanted to resize the camera's input feed and capture photos. I hope it works for you as well.
从代码创建一个 UIImagePickerController,调整其属性,在其上添加覆盖层,然后使用控制器控制覆盖层上您想要的任何内容:自定义控件、覆盖图像等...
这给出了类似这样的内容:
OverlayViewController< /code> 是您必须编写的控制器,用于控制添加到覆盖层上的所有内容。
pickerReference
是您可以保留以向相机发送订单的属性。例如,您可以从来自放置在覆盖层上的 UIButton 的 IBAction 调用以下内容:Create a UIImagePickerController from code, adjust its properties, add an overlay onto it, and with you controller, control whatever you want on that overlay : custom controls, overlaying images, etc...
That gives something like this :
OverlayViewController
is the controller that you must write to control everything you add onto the overlay.pickerReference
is a property you can keep to send orders to the camera. For example, you could call the following from an IBAction coming from a UIButton placed onto the overlay :阅读 UIImagePickerController 类参考,文档中就是这样……
有一些属性,特别是
cameraOverlayView
和showsCameraControls
属性。因此,您可以隐藏控件,提供自定义覆盖视图,并向此自定义视图添加子视图以添加自定义按钮、框架等。
Read the UIImagePickerController Class Reference, that's right in the documentation…
There are properties for this, especially the
cameraOverlayView
andshowsCameraControls
properties.So you can hide the controls, provide a custom overlay view, and add subviews to this custom view to add custom buttons, frames, etc.
Oliver 的 Swift 3 版本答案:
OverlayViewController 协议:
Swift 3 version for answer from Oliver:
OverlayViewController protocols: