将cameraOverlayView与UIImagePickerController一起使用

编程入门 行业动态 更新时间:2024-10-10 01:27:14
本文介绍了将cameraOverlayView与UIImagePickerController一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我知道这已被问了很多次,但我找不到答案。

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一起使用

本文发布于:2023-11-25 20:23:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631220.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:cameraOverlayView   UIImagePickerController

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!