• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

cameraOverlayView和UIImagePickerController使用

用户头像
it1352
帮助1

问题说明

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

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.

正确答案

#1

以下是代码:

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):

快乐编码:)

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcffige
系列文章
更多 icon
同类精品
更多 icon
继续加载