我知道这已被问了很多次,但我找不到答案。
I know this has been asked a number of time but I can't find an answer.
我有一个使用的应用程序UIImagePickerController 拍照。问题是我只想要相机选项可用,我知道我需要隐藏标准控件:
I have an app that uses the UIImagePickerController to take a picture. The problem is that I only want the camera option to be available and I understand that I need to hide the standard controls:
cameraUI.showsCameraControls=NO;并使用 cameraOverlayView 提供我自己的控制。我已经看过Apple的 PhotoPicker 项目了,我最初的问题是如何将 Overlay 对象放到我的身上故事情节?我在图书馆找不到这样的对象。感谢任何帮助。
and use a cameraOverlayView to provide my own controls. I have had a look at Apple's PhotoPicker project already and my initial problem is how do I get an Overlay object onto my storyboard? I can't find such an object in the library. Any help gratefully received.
推荐答案以下是代码:
toolBar=[[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height-54, self.view.frame.size.width, 55)]; toolBar.barStyle = UIBarStyleBlackOpaque; NSArray *items=[NSArray arrayWithObjects: [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelPicture)], [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(shootPicture)], [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], nil]; [toolBar setItems:items]; // create the overlay view overlayView = [[OverlayView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-44)]; // important - it needs to be transparent so the camera preview shows through! overlayView.opaque=NO; overlayView.backgroundColor=[UIColor clearColor]; // parent view for our overlay UIView *cameraView=[[UIView alloc] initWithFrame:self.view.bounds]; [cameraView addSubview:overlayView]; [cameraView addSubview:toolBar]; imagePickerController = [[UIImagePickerController alloc] init]; if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] == NO){ NSLog(@"Camera not available"); return; } imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera; imagePickerController.delegate = self; // hide the camera controls imagePickerController.showsCameraControls=NO; imagePickerController.wantsFullScreenLayout = YES; [imagePickerController setCameraOverlayView:cameraView]; [self presentViewController:imagePickerController animated:YES completion:nil];在头文件中声明:
UIImagePickerController * imagePickerController; UIToolbar *toolBar; OverlayView *overlayView;从Apples PhotoPicker添加此OverlayView.h和.m类。
Add this OverlayView.h and .m Class from Apples PhotoPicker.
使用自定义相机按钮拍摄照片的操作:
Actions for capturing photo using custom camera button:
-(void) shootPicture { [imagePickerController takePicture]; } - (IBAction)cancelPicture { [self dismissViewControllerAnimated:YES completion:nil]; }输出将如下图所示(我添加了一个捕获按钮和自定义叠加视图中的取消按钮):
Output will come like this below attached screenshot (I have added a capture button and cancel button in custom overlay view):
快乐编码:)
更多推荐
将cameraOverlayView与UIImagePickerController一起使用
发布评论