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

3

尽管我已将userInteractionsEnabled设置为NO,而且我的叠加框明显没有重叠按钮,但我仍无法点击它们。

截屏

代码:

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

有什么想法吗?

1
你把 userInteractionsEnabled 设为 NO 了吗?那是不对的。另一个可能性是你的按钮框架太小了,这会绘制出按钮,但它们无法被触摸。 - Krumelur
你在按钮或整个视图中设置了userInteractionEnabled吗?无论哪种情况都不会起作用。首先,你可能有这个想法,其次,如果视图不可访问,那么如何访问视图的子视图呢? - Raviraj Jadeja
我已经添加了上面的代码。正如您所看到的,我只将setUserInteractionEnabled设置为覆盖层。这些按钮来自iOS提供的标准UIImagePickerController。如果我不使用覆盖层,它们可以正常工作。 - Michel
解决了!我不得不将:[picker.cameraOverlayView addSubview:overlayIV];更改为:picker.cameraOverlayView = overlayIV;谢谢大家的帮助! - Michel
2个回答

1
将此更改为:[picker setCameraOverlayView:overlayIV];

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接