UIImagePickerController-iOS11+左下角取消按钮点击不响应解决方案

UIImagePickerController的delegate类中实现UINavigationControllerDelegate代理中的方法:

-(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated;

Swift
    func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
        
        if #available(iOS 11, *) {
            if viewController.isKind(of: NSClassFromString("PUPhotoPickerHostViewController")!) {
                
                for view: UIView in viewController.view.subviews {
                    if view.frame.size.width < 42 {
                        viewController.view.sendSubviewToBack(view)
                    }
                    
                }
            }
        }else{
            return
        }
    }
Objective-C
-(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) {
            // iOS 11之后,图片编辑界面最上层会出现一个宽度<42的view,会遮盖住左下方的cancel按钮,使cancel按钮很难被点击到,故改变该view的层级结构
            if (obj.frame.size.width < 42) {
                [viewController.view sendSubviewToBack:obj];
                *stop = YES;
            }
        }];
    }
}

推荐阅读更多精彩内容