[英]iOS 7 UIImagePickerController with Overlay - retake and use photo not usable
Even though I set userInteractionsEnabled to NO and my overlayframe is cleary not overlapping the buttons, I cannot click them. 即使我将userInteractionsEnabled设置为NO并且我的overlayframe是清晰的而不是按钮重叠,我也无法点击它们。
Code: 码:
// 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];
Any ideas? 有任何想法吗?
change this: [picker.cameraOverlayView addSubview:overlayIV];
改变这个:
[picker.cameraOverlayView addSubview:overlayIV];
to: [picker setCameraOverlayView:overlayIV];
to:
[picker setCameraOverlayView:overlayIV];
i had the same problem, but my solution was slightly different. 我有同样的问题,但我的解决方案略有不同。 i was using xib files and the appropriate views and buttons were indeed in the correct hierarchy.
我正在使用xib文件,相应的视图和按钮确实在正确的层次结构中。
but i had to dynamically create a temporary view after the main parent view loaded (viewDidLoad) and add this temp view as the camera overlay. 但是我必须在加载主父视图(viewDidLoad)后动态创建临时视图,并将此临时视图添加为相机覆盖。 then i added the buttons as a subview to this temp view.
然后我将按钮作为子视图添加到此临时视图中。
- (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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.