美文网首页笔记篇
笔记篇章 适配iOS 14 'HXPhotoPicker',

笔记篇章 适配iOS 14 'HXPhotoPicker',

作者: 失忆的程序员 | 来源:发表于2021-05-21 14:55 被阅读0次

    问题一:安卓上传的 webp 图片,无法显示

    问题二:适配iOS 14 'HXPhotoPicker', '2.4.2'

    问题一:

    关于安卓上传的 webp 图片,无法显示,
    我的版本 pod 'HXPhotoPicker', '2.4.2'#3.0.3, (2.4.2 pod 'SDWebImage','~> 4.2.2')
    我的解决版本是:

    #YYWebImage支持webp格式的图片
    pod 'YYImage/WebP'

    代码:

    YYWebImageManager *manager = [YYWebImageManager sharedManager];
    NSString *key = [manager cacheKeyForURL:[NSURL URLWithString:imageModels.picture]];
    YYImageCache *cache = [YYImageCache sharedCache];
    UIImage *image = [cache getImageForKey:key];
    if (image) {

    } else {

    [[YYWebImageManager sharedManager] requestImageWithURL:[NSURL URLWithString:地址] options:YYWebImageOptionAvoidSetImage progress:^(NSInteger receivedSize, NSInteger expectedSize) {
    } transform:^UIImage * _Nullable(UIImage * _Nonnull image, NSURL * _Nonnull url) {
    return image;
    } completion:^(UIImage * _Nullable image, NSURL * _Nonnull url, YYWebImageFromType from, YYWebImageStage stage, NSError * _Nullable error) {
    nslog(@"%@", image);
    if (!error) { 

    }

    }

    代码粘贴区域:

    /*

    - (void)presentPreviewPhotoWithVideoUrl:(NSURL *)videoUrl Index:(NSInteger)index

    {

        NSMutableArray *tempArr = [NSMutableArray array];

        if (_detailModels.video.length > 0) {

            HXCustomAssetModel *videoModels = [HXCustomAssetModel assetWithLocalVideoURL:videoUrl selected:YES];

            [tempArr addObject:videoModels];

        }

        // 创建队列组,可以使多个网络请求异步执行,执行完之后再进行操作

        dispatch_group_t group = dispatch_group_create();

        //创建全局队列

        dispatch_queue_t queue = dispatch_get_global_queue(0, 0);

        dispatch_group_async(group, queue, ^{

            for (MerchantDetailImageModels *imageModels in _detailModels.bannerpiclist)

            {

                dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);

                YYWebImageManager *manager = [YYWebImageManager sharedManager];

                NSString *key = [manager cacheKeyForURL:[NSURL URLWithString:imageModels.picture]];

                YYImageCache *cache = [YYImageCache sharedCache];

                UIImage *image = [cache getImageForKey:key];

                if (image)

                {

                    HXCustomAssetModel *models = [HXCustomAssetModel assetWithLocalImage:image selected:YES];

                    models.localImage = image;

                    [tempArr addObject:models];

                    dispatch_semaphore_signal(semaphore);

                }

                else

                {

                    [[YYWebImageManager sharedManager] requestImageWithURL:[NSURL URLWithString:imageModels.picture] options:YYWebImageOptionAvoidSetImage progress:^(NSInteger receivedSize, NSInteger expectedSize) {

                    } transform:^UIImage * _Nullable(UIImage * _Nonnull image, NSURL * _Nonnull url) {

                        return image;

                    } completion:^(UIImage * _Nullable image, NSURL * _Nonnull url, YYWebImageFromType from, YYWebImageStage stage, NSError * _Nullable error) {

                        XPFLog(@"%@", image);

                        if (!error) {

                            HXCustomAssetModel *models = [HXCustomAssetModel assetWithLocalImage:image selected:YES];

                            models.localImage = image;

                            [tempArr addObject:models];

                            dispatch_semaphore_signal(semaphore);

                        }

                    }];

                }

            }

        });

        // 当所有队列执行完成之后

        dispatch_group_notify(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

            // 返回主线程进行界面上的修改

            dispatch_async(dispatch_get_main_queue(), ^{

                HXPhotoManager *photoManager = [HXPhotoManager managerWithType:HXPhotoManagerSelectedTypePhotoAndVideo];

                photoManager.configuration.saveSystemAblum = YES;

                photoManager.configuration.photoMaxNum = 0;

                photoManager.configuration.videoMaxNum = 0;

                photoManager.configuration.maxNum = 10;

                photoManager.configuration.selectTogether = YES;

                photoManager.configuration.photoCanEdit = NO;

                photoManager.configuration.videoCanEdit = NO;

                [photoManager addCustomAssetModel:tempArr];

                [[ViewTool topViewController] hx_presentPreviewPhotoControllerWithManager:photoManager previewStyle:HXPhotoViewPreViewShowStyleDark currentIndex:index photoView:nil];

            });

        });

    }

    */

    问题二:

    iOS 14 以下版本
    pod 'HXPhotoPicker', '2.4.2'#3.0.3, (2.4.2 pod 'SDWebImage','~> 4.2.2')
    图层 来看 YYAnimatedImageView
    当我iOS 14 以上(含)
    pod 'HXPhotoPicker', '3.0.3'#2.4.2, (3.0.3 pod 'SDWebImage','~> 5.0.0')
    图层 来看 SDAnimatedImageView

    图片展示不出来,

    解决方法,在 YYAnimatedImageView 的 - (void)displayLayer:(CALayer *)layer 方法 里 适配了一下 iOS 14 ,

    - (void)displayLayer:(CALayer *)layer {
      if (_curFrame) {
         layer.contents = (__bridge id)_curFrame.CGImage;
      } else {
        if (@available(iOS 14.0, *)) {
            [super displayLayer:layer];
        }
      }
    }

    附件图

    这个样子

     HXPhotoPicker

    相关文章

      网友评论

        本文标题:笔记篇章 适配iOS 14 'HXPhotoPicker',

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