UIButton里面的UIButPickerController.cameraOverlayView没有响应

时间:2014-12-16 05:37:38

标签: ios uibutton uiimagepickercontroller overlay-view cameraoverlayview

我在UIView中有一个UIButton,我将其设置为cameraOverlayView。

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

enter image description here

这是我的代码:

 // 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];
}

这是我的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)

编辑:添加叠加信息

enter image description here

我在网上搜索过类似的帖子(例如UIImagePickerController Overlay Buttons Not Firing),但没有找到任何解决方案。

你可以在图片中看到的UIButton在UIView里面,这是分配给cameraOverlayView的代码中的overlayView。它也通过一个插座连接到cameraButtonPressed:动作,如果我不添加UIImagePickerController它就可以正常工作。

它没有回应我不知道为什么的任何接触。

有谁知道发生了什么?

1 个答案:

答案 0 :(得分:0)

我已经解决了我的问题,但我相信这是一个粗略的方式:

[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];
}];

稍后可能会回到此问题并发布更新以防我找到更好的解决方案。