[英]iOS 11 UIImagePickerController after selection cancel button bug
I'm using UIImagePickerController to select the photo and crop image.我正在使用 UIImagePickerController 来选择照片和裁剪图像。
This is the same situation as seen at https://forums.developer.apple.com/thread/88286这与https://forums.developer.apple.com/thread/88286 上看到的情况相同
Here is my code:这是我的代码:
- (void) onTest:(UIButton *)btn {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
picker.delegate = self;
picker.allowsEditing = YES;
[picker setModalPresentationStyle: UIModalPresentationOverCurrentContext];
[self presentViewController:picker animated:YES completion:nil];
}
This is view layer.这是视图层。 I did not add this UIView.
我没有添加这个 UIView。 I can't press the cancel button and I can't zoom in/out.
我无法按下取消按钮,也无法放大/缩小。
There is no problem with iOS 10. I only have a problem with iOS 11. iOS 10没有问题,我只有iOS 11有问题。
I have a good idea to address this issue.我有一个好主意来解决这个问题。
Set the controller (from which you show the UIImagePickerController
) as the delegate for the UIImagePickerController
, then conforms the UINavigationControllerDelegate
since UIImagePickerController
is the subclass of UINavigationController
, then implement the method:设置控制器(从中显示
UIImagePickerController
)为代表的UIImagePickerController
,则符合该UINavigationControllerDelegate
以来UIImagePickerController
是子类UINavigationController
,然后实现方法:
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
if ([UIDevice currentDevice].systemVersion.floatValue < 11) {
return;
}
if ([viewController isKindOfClass:NSClassFromString(@"PUPhotoPickerHostViewController")]) {
weakify(viewController);
[viewController.view.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (obj.frame.size.width < 42 && FLOAT_EQUAL(obj.frame.size.height, [[UIScreen mainScreen] bounds].size.height)) {
strongify(viewController);
[viewController.view sendSubviewToBack:obj];
*stop = YES;
}
}];
}
}
- (IBAction)addPhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
Use this delegate :-使用这个委托:-
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
Use this code to open Photo library:使用此代码打开照片库:
UIImagePickerController *pickerView = [[UIImagePickerController alloc] init];
pickerView.allowsEditing = YES;
pickerView.delegate = self;
[pickerView setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:pickerView animated:YES completion:nil];
And use this delegate to get the cropped image to your view controller:并使用此委托将裁剪后的图像发送到您的视图控制器:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
UIImage *image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.