UIImagePickerController.cameraOverlayView中的UIButton没有响应 [英] UIButton inside UIImagePickerController.cameraOverlayView not responding

查看:174
本文介绍了UIImagePickerController.cameraOverlayView中的UIButton没有响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在设置为cameraOverlayView的UIView中有一个UIButton.

I have got a UIButton inside a UIView that I set as the cameraOverlayView.

我还缩放了uiimagepicker cameraView以覆盖整个屏幕(如下图所示).

I also scaled the uiimagepicker cameraView to cover the whole screen (as you can see below in the picture).

这是我的代码:

 // CameraViewController.m

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    if(!self.imagePickerController)
        [self setupCamera];
}

-(void)setupCamera{
    self.imagePickerController = [[UIImagePickerController alloc] init];
    self.imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
    self.imagePickerController.delegate = self;
    self.imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
    self.imagePickerController.showsCameraControls = NO;

    self.imagePickerController.cameraOverlayView =  self.overlayView;

    [self scaleCameraPreview];

    // Present picker in the next loop (to avoid warning - "Presenting view controllers on detached view controllers is discouraged")
    [self performSelector:@selector(presentPicker) withObject:nil afterDelay:0.0];
}

-(void)presentPicker{
    [self presentViewController:self.imagePickerController animated:NO completion:nil];
}

-(void)scaleCameraPreview{
    CGSize screenSize = [[UIScreen mainScreen] bounds].size;

    int heightOffset = 0;

    if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
    {
        heightOffset = 120;
    }

    float cameraAspectRatio = 4.0 / 3.0;
    float imageWidth = floorf(screenSize.width * cameraAspectRatio);
    float scale = ceilf(((screenSize.height + heightOffset) / imageWidth) * 10.0) / 10.0;
    self.imagePickerController.cameraViewTransform = CGAffineTransformMakeScale(scale, scale);
}

-(IBAction)cameraButtonPressed:(id)sender{
    [self.imagePickerController takePicture];
}

这是我的视图控制器层次结构:

And this is my hierarchy of viewcontrollers:

- UINavigationController 
   - SWRevealViewController (manages a drawer functionality between different controllers)
     - UINavigationController (current controller for the camera)
       - CameraViewController 
         - PickerViewController (Presented modally as you can see above) 
           - PhotoTakenViewController (Controller that will fire after UIImagePicker returns an image)

添加叠加层信息

我已经在线搜索了类似的线程(例如 UIImagePickerController覆盖按钮未触发)但没有找到任何解决方案.

I have searched online for similar threads (e.g. UIImagePickerController Overlay Buttons Not Firing) but didn't find any solution.

您可以在图片中看到的UIButton在UIView内,这是分配给cameraOverlayView的代码中的overlayView.它还通过插座连接到cameraButtonPressed:动作,如果我不添加UIImagePickerController,它也可以完美工作.

The UIButton that you can see in the picture, is inside a UIView this is the overlayView in the code assigned to the cameraOverlayView. It is also connected to the cameraButtonPressed: action through an outlet, and it works perfectly if I don't add the UIImagePickerController.

它不响应任何我不知道为什么的触摸.

It isn't responding to any touches I don't know why.

有人知道发生了什么事吗?

推荐答案

我已经解决了问题,但我以粗略的方式相信:

I've fixed my issue but I believe in a sketchy way:

[self presentViewController:self.imagePickerController animated:NO completion:^(void){

    // Re-add the button so it is on top of the overlay
    [self.imagePickerController.view addSubview:self.takePhotoButton];
}];

稍后可能会再提到此问题,并发布更新,以防万一我找到更好的解决方案.

Will probably come back later to this issue and post an update in case I find a better solution.

这篇关于UIImagePickerController.cameraOverlayView中的UIButton没有响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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