[英]iPhone sdk - Use a custom camera
I'm developing an app that needs to take two pictures in a row. 我正在开发一个需要连续拍摄两张照片的应用。 I'm currently using the iPhone camera but :
我目前正在使用iPhone相机,但是:
What should I do ? 我该怎么办 ? Should I make my own camera ?
我应该自己制作相机吗? I couldn't find an easy tutorial for a custom camera with only a "take picture" button...
我找不到一个只有“拍照”按钮的自定义相机的简单教程......
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... 从代码创建
UIImagePickerController
,调整其属性,在其上添加叠加,并与您的控制器,控制在该叠加上你想要的任何内容:自定义控件,覆盖图像等...
That gives something like this : 这给出了这样的东西:
self.picker = [[UIImagePickerController alloc] init];
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
self.picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
self.picker.showsCameraControls = NO;
self.picker.navigationBarHidden = YES;
self.picker.toolbarHidden = YES;
self.picker.wantsFullScreenLayout = YES;
// Insert the overlay
self.overlay = [[OverlayViewController alloc] initWithNibName:@"Overlay" bundle:nil];
self.overlay.pickerReference = self.picker;
self.picker.cameraOverlayView = self.overlay.view;
self.picker.delegate = self.overlay;
[self presentModalViewController:self.picker animated:NO];
OverlayViewController
is the controller that you must write to control everything you add onto the overlay. OverlayViewController
是您必须编写的控制器,用于控制添加到叠加层中的所有内容。
pickerReference
is a property you can keep to send orders to the camera. pickerReference
是您可以保留向相机发送订单的属性。 For example, you could call the following from an IBAction
coming from a UIButton
placed onto the overlay: 例如,您可以从放置在叠加层上的
UIButton
的IBAction
调用以下内容:
[self.pickerReference takePicture];
The easiest way to do it is to use UIImagePickerController with showsCameraControls
set to NO and a custom view set in cameraOverlayView
; 最简单的方法是使用UIImagePickerController,将
showsCameraControls
设置为NO,并在cameraOverlayView
设置自定义视图; this view can have whatever buttons you need on it. 这个视图可以有你需要的任何按钮。 When touched, the button should call
takePicture
on the image picker, and when you're done just use dismissModalViewControllerAnimated:
to dismiss the picker. 触摸时,按钮应该在图像选择器上调用
takePicture
,当你完成后,只需使用dismissModalViewControllerAnimated:
来关闭选择器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.