带有覆盖的iOS 7 UIImagePickerController - 重新拍摄并使用不可用的照片

时间:2013-12-11 12:54:49

标签: ios iphone ios7 uiimagepickercontroller

即使我将userInteractionEnabled设置为NO并且我的覆盖框架显然没有与按钮重叠,我也无法点击它们。

Screenshot

代码:

    // Init Picker
    UIImagePickerController* picker = [[UIImagePickerController alloc] init];

    //Create camera overlay for square pictures
    CGFloat navigationBarHeight = picker.navigationBar.bounds.size.height + 25;
    CGFloat height = picker.view.bounds.size.height - 2 * navigationBarHeight;
    CGFloat width = picker.view.bounds.size.width;
    CGRect f = CGRectMake(0, navigationBarHeight, width, height);
    CGFloat barHeight = (f.size.height - f.size.width) / 2;
    UIGraphicsBeginImageContext(f.size);
    [[UIColor colorWithRed:0 green:0 blue:0 alpha:0.7] set];
    UIRectFillUsingBlendMode(CGRectMake(0, 0, f.size.width, barHeight), kCGBlendModeNormal);
    UIRectFillUsingBlendMode(CGRectMake(0, f.size.height - barHeight, f.size.width, barHeight - 4), kCGBlendModeNormal);
    UIImage *overlayImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    UIImageView *overlayIV = [[UIImageView alloc] initWithFrame:f];

    // Disable all user interaction on overlay
    [overlayIV setUserInteractionEnabled:NO];
    [overlayIV setExclusiveTouch:NO];
    [overlayIV setMultipleTouchEnabled:NO];

    // Map generated image to overlay
    overlayIV.image = overlayImage;

    // Present Picker
    picker.modalPresentationStyle = UIModalPresentationCurrentContext;
    picker.delegate = self;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    if([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront]) {
        picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
    }
    [picker.cameraOverlayView addSubview:overlayIV];

    [self presentViewController:picker animated:YES completion:nil];

有什么想法吗?

2 个答案:

答案 0 :(得分:1)

更改此内容:[picker.cameraOverlayView addSubview:overlayIV];

至:[picker setCameraOverlayView:overlayIV];

答案 1 :(得分:0)

我有同样的问题,但我的解决方案略有不同。我正在使用xib文件,相应的视图和按钮确实在正确的层次结构中。

但我必须在加载主父视图(viewDidLoad)后动态创建临时视图,并将此临时视图添加为相机覆盖。然后我将按钮作为子视图添加到此临时视图中。

 - (void)viewDidLoad
 {
   ImgPicker = [[UIImagePickerController alloc] init]; 

   if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

    // note: need to set a manually created view (vOverlay) as the image picker overlay,
    //  and then add the button controls (vControls) to this manually created vOverlay.
    //  Otherwise, the buttons in vControls are not clickable
     UIView *tempView = [[UIView alloc] initWithFrame:ImgPicker.view.frame];
     [tempView addSubview:self.vButtons];

     ImgPicker.cameraOverlayView = tempView;
    }
 }