美文网首页
presentLimitedLibraryPickerFromV

presentLimitedLibraryPickerFromV

作者: follow_er | 来源:发表于2021-03-10 20:21 被阅读0次

    iOS14相册权限进行了改变,下面是调用起系统相册的方式,弹起是正常的,但是界面有比较奇怪的变化,搜索栏是透明的,要点击一次,才能正常显示。
    如果你也遇到类似问题,希望这个文章能有帮到你们。


    06b9b1a4c8918163d6c9f63d4d0c8d32_image_1615279034646.png
    - (void)checkAlbumPermission {
    
       if (@available(iOS 14, *)) {
           __weak PhotoCollectionController *weakSelf = self;
           PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatusForAccessLevel:PHAccessLevelReadWrite];
           if (status == PHAuthorizationStatusLimited) {
               weakSelf.addButton.hidden = NO; // 添加图片按钮不隐藏
           }
       }
       
    //    if (@available(iOS 14, *)) {
    //        [PHPhotoLibrary requestAuthorizationForAccessLevel:PHAccessLevelReadWrite handler:^(PHAuthorizationStatus status) {
    //            switch (status) {
    //                case PHAuthorizationStatusLimited:
    //                {
    //                    [self selectAlbum];
    //                }
    //                    break;
    //                case PHAuthorizationStatusDenied:
    //                case PHAuthorizationStatusRestricted:
    //                {
    //                    [self alertAlbum];
    //                }
    //                default:
    //                {
    //                    [self selectAlbum];
    //                }
    //                    break;
    //            }
    //        }];
    //    } else {
    //        // Fallback on earlier versions
    //    }
    }
    
    // 点击按钮调用的方法
    - (void)selectAlbum {
        //判断相册是否可用
        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
            self.imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            if (@available(iOS 14, *)) {
                [[PHPhotoLibrary sharedPhotoLibrary] presentLimitedLibraryPickerFromViewController:self];
            }else {
                [self presentViewController:self.imagePickerController animated:YES completion:^{
                }];
            }
    
        }
    }
    

    原因是:[[UINavigationBar appearance] setBackgroundImage:bgImage forBarMetrics:UIBarMetricsDefault]; 设置背景图片的时候影响到系统了。
    最后解决方式是对iOS13的UINavigationBar的新特性适配。

    [[UINavigationBar appearance] setTranslucent:NO]; //对iOS13之后的控制器高度有影响,所以这个放在外面设置
        if (@available(iOS 13.0, *)) {
            UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
            [appearance configureWithDefaultBackground];
            appearance.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor grayColor], NSFontAttributeName:[UIFont systemFontOfSize:17]};
            UIImage *bgImage = [UIImage resizableImageWithColor:[UIColor lightGrayColor]]; // 自定的方法,获取图片,你们加载自己的图片就可以了
            appearance.backgroundImage = bgImage;
            appearance.backgroundColor = [UIColor lightGrayColor];
            [UINavigationBar appearance].standardAppearance = appearance;
        } else {
        //    [[UINavigationBar appearance] setOpaque:YES];
            [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor grayColor], NSFontAttributeName:[UIFont systemFontOfSize:17]}];
            //替换bar最下面的得阴影
            UIImage *bgImage = [UIImage resizableImageWithColor:[UIColor lightGrayColor]]; // 自定的方法,获取图片,你们加载自己的图片就可以了 
            [[UINavigationBar appearance] setBackgroundImage:bgImage forBarMetrics:UIBarMetricsDefault];
            [[UINavigationBar appearance] setBarTintColor:[UIColor lightGrayColor]];
        }
    
    

    参考文章:https://www.jianshu.com/p/bd038bf2373e

    相关文章

      网友评论

          本文标题:presentLimitedLibraryPickerFromV

          本文链接:https://www.haomeiwen.com/subject/vecgqltx.html