zoukankan      html  css  js  c++  java
  • 关于IOS某图片添加控件,图片从相册或拍照保存后,再次进入时点击放大图无法显示的问题

    某图片添加控件:

    https://github.com/XZTLLQ/LQPhotoPickerDemo

    问题:

    标题已说明

    代码块:

    NSArray *alAssetUrl =(NSMutableArray *)[HiddenRecordDataService getLocalImageSystemFilePath:_hiddenDangerInfoLocalModel.HiddenDangerInfoLocalId];
        NSMutableArray *localASSetArray = [NSMutableArray arrayWithCapacity:0];
        for (NSURL *url in alAssetUrl) {
            NSLog(@"url:%@", url);
            ALAssetsLibrary* library = [[ALAssetsLibrary alloc]init];
            // library fetch
                [library assetForURL:url resultBlock:^(ALAsset *asset) {
                    if (asset) {
                        [localASSetArray addObject:asset];
                    } else {
                        // On iOS 8.1 [library assetForUrl] Photo Streams always returns nil. Try to obtain it in an alternative way
                    }
                } failureBlock:^(NSError *error) {
                    iToast *itoast = [iToast makeText:@"获取图片失败"];
                    [itoast show];
                }];
        }

    问题是由于标红代码导致,这里的ALAssetsLibrary对象需要用单例

    代码如下:

    NSArray *alAssetUrl =(NSMutableArray *)[HiddenRecordDataService getLocalImageSystemFilePath:_hiddenDangerInfoLocalModel.HiddenDangerInfoLocalId];
        
        NSMutableArray *localASSetArray = [NSMutableArray arrayWithCapacity:0];
        
        for (NSURL *url in alAssetUrl) {
            NSLog(@"url:%@", url);
            //ALAssetsLibrary* library = [[ALAssetsLibrary alloc]init];
            ALAssetsLibrary* library = [HiddenRecordViewController defaultAssetsLibrary];
    //        library fetch
                [library assetForURL:url resultBlock:^(ALAsset *asset) {
                    if (asset) {
                        [localASSetArray addObject:asset];
                    } else {
                        // On iOS 8.1 [library assetForUrl] Photo Streams always returns nil. Try to obtain it in an alternative way
                    }
                    
                } failureBlock:^(NSError *error) {
                    iToast *itoast = [iToast makeText:@"获取图片失败"];
                    [itoast show];
                }];
            
        }
    defaultAssetsLibrary代码:
    + (ALAssetsLibrary *)defaultAssetsLibrary {
        static dispatch_once_t pred = 0;
        static ALAssetsLibrary *library = nil;
        dispatch_once(&pred, ^{
            library = [[ALAssetsLibrary alloc] init];
        });
        return library;
    }
     
  • 相关阅读:
    Invalid bound statement (not found): com.**.demo.mapper.User_infoMapper
    IDEA 常用快捷键
    springboot 将项目打包成jar包
    .netcore A circular dependency was detected for the service of type '****'.
    C# 枚举 高级战术
    C#高性能动态获取对象属性值
    使用github actions检测网站是否在线
    纸壳CMS分布式部署集群解决方案
    System.Data.DataRow[] 如何转换为 DataTable
    JavaDoc生成文档
  • 原文地址:https://www.cnblogs.com/royi123/p/7600287.html
Copyright © 2011-2022 走看看