当点击叠加层中的按钮时,带有cameraOverlayView的UIImagePickerController会聚焦 [英] UIImagePickerController with cameraOverlayView focusses when button in overlay is tapped

查看:177
本文介绍了当点击叠加层中的按钮时,带有cameraOverlayView的UIImagePickerController会聚焦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Objective C的新手,这是我在这里发布的第一个问题,因此这可能是世界上最容易回答的问题,但我无法弄清楚.

I'm new to Objective C and it's my first question I'm posting here so this is probably the easiest question in the world to answer, but I couldn't figure this one out.

我正在尝试创建一个使用相机的iOS应用.我正在使用UIImagePickerController类显示相机并拍照,但是我创建了一个自定义UIView,其中包含一堆UIButton实例,这些实例使用cameraOverlayView属性覆盖了相机预览框架.我正在使用一种方法使用以下代码将相机放置在屏幕上:

I am trying to create an iOS app that uses the camera. I'm using the UIImagePickerController class to display the camera and take pictures, but I've created a custom UIView that contains a bunch of UIButton instances which overlay the camera preview frame, using the cameraOverlayView property. I'm using the a method to put the camera on screen with this code:

- (BOOL) startCameraControllerFromViewController: (UIImagePickerController*) imagePickerController
                               usingDelegate: (id <UIImagePickerControllerDelegate,
                                               UINavigationControllerDelegate>) imagePickerControllerDelegate {

if (([UIImagePickerController isSourceTypeAvailable:
      UIImagePickerControllerSourceTypeCamera] == NO)
    || (imagePickerController == nil)
    || (imagePickerControllerDelegate == nil))
    return NO;

imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;

imagePickerController.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeImage, nil];

imagePickerController.allowsEditing = NO;
imagePickerController.showsCameraControls = NO;
imagePickerController.wantsFullScreenLayout = YES;

imagePickerController.delegate = imagePickerControllerDelegate;

self.cameraOverlayViewController = [[CameraOverlayViewController alloc] initWithImagePickerControllerDelegate:imagePickerController nibName:@"CameraOverlayView" bundle:nil];
self.cameraOverlayViewController.view.frame = CGRectMake(0, 0, imagePickerController.view.frame.size.width, imagePickerController.view.frame.size.height);
imagePickerController.cameraOverlayView = self.cameraOverlayViewController.view;

[self presentViewController:imagePickerController animated:self.showCameraAnimation completion:^(void) {
    [self.view bringSubviewToFront:self.cameraOverlayViewController.view];
}];

return YES;

}

当我按下位于摄像头预览窗口顶部的按钮时,将触发相应的IBAction,但也会敲击底层的摄像头视图并重新对焦.因此,每次按下按钮时,我都必须手动重新调整相机预览的对焦,然后才能拍照.如您所见,我尝试使用BringSubViewToFront :,但这似乎不起作用.

When I press a button that is located on top of the camera preview window, the corresponding IBAction gets triggered, but the underlaying camera view also gets tapped and refocusses. So every time I press a button I have to manually refocus the camera preview before I can take a picture. As you can see I've tried to use bringSubViewToFront:, but that doesn't seem to work.

当我点击cameraOverlayView上的按钮时,如何防止相机聚焦?

How do I prevent the camera from focussing when I tap a button on the cameraOverlayView?

感谢您的帮助!

推荐答案

将此添加到您的代码中:

Add this to your code:hitTest:withEvent:

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    UIView *hittedView = [super hitTest:point withEvent:event];
    return hittedView == self.button ? hittedView : nil;
}

我提到了这一点: >仅对子视图启用UserInteraction .我已经测试了代码.而且有效!

I refered to this: UserInteraction enable for subview only. I've tested the code. And it works!

这篇关于当点击叠加层中的按钮时,带有cameraOverlayView的UIImagePickerController会聚焦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆