![](/img/trans.png)
[英]UIImagePickerController Use Photo / Retake buttons don't work
[英]iOS 7 UIImagePickerController with Overlay - retake and use photo not usable
即使我將userInteractionsEnabled設置為NO並且我的overlayframe是清晰的而不是按鈕重疊,我也無法點擊它們。
碼:
// 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];
有任何想法嗎?
改變這個: [picker.cameraOverlayView addSubview:overlayIV];
to: [picker setCameraOverlayView:overlayIV];
我有同樣的問題,但我的解決方案略有不同。 我正在使用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;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.