简体   繁体   English

iPhone sdk - 使用自定义相机

[英]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相机,但是:

  • I would like to NOT have the cancel button on the bottom left 我想在左下方没有取消按钮
  • I would like to NOT have the preview of my picture (with the blue button "use"). 我想不要预览我的照片(使用蓝色按钮“使用”)。

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: 例如,您可以从放置在叠加层上的UIButtonIBAction调用以下内容:

[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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM