问题:在 iOS 11 下,如果给 UIImagePickerController 设置 allowsEditing = YES,然后在编辑图片的时候,却发现左下角的那个 取消 按键怎么也没法点击到
原因:image.png
解决办法:
///oc版本
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
if ([UIDevice currentDevice].systemVersion.floatValue < 11) {
return;
}
if ([viewController isKindOfClass:NSClassFromString(@"PUPhotoPickerHostViewController")]) {
[viewController.view.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (obj.frame.size.width < 42) {
[viewController.view sendSubviewToBack:obj];
*stop = YES;
}
}];
}
}
///swift版本
/// iOS11 解决图片编辑时左下角cancel按钮很难点击的问题
func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
if Double(UIDevice.current.systemVersion)! < 11.0 {
return
}
if viewController.isKind(of: NSClassFromString("PUPhotoPickerHostViewController")!) {
for item in viewController.view.subviews {
if item.frame.size.width < 42 {
viewController.view.sendSubview(toBack: item)
return
}
}
}
}