【问题标题】:Is there a way to access ALAssets information outside of resultBlock?有没有办法在 resultBlock 之外访问 ALAssets 信息?
【发布时间】:2013-11-04 21:29:15
【问题描述】:

好的,所以我设置了 ImagePicker 所有设置和 ALAssetLibrary 设置来获取图片和标题(如果现有图片存在或新图片的通用文本存在)但现在我想弄清楚是否有办法我可以通过assetForURL 方法在块调用之外访问此信息。所以这是我的代码,以便我可以显示正在发生的事情(这是在选择图片后显示的屏幕的 viewDidLoad 方法中)

__block NSString *documentName;
    __block UIImage *docImage;
    NSURL *resourceURL = [imageInfo  objectForKey:UIImagePickerControllerReferenceURL];
    ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *asset)
    {
        ALAssetRepresentation *imageRep = [asset defaultRepresentation];
        //Get Image
        CGImageRef iref = [imageRep fullResolutionImage];
        //If image is null then it's a new picture from Camera
        if (iref == NULL) {
            docImage = [imageInfo objectForKey:UIImagePickerControllerOriginalImage];
            documentName = @"New Picture";
        }
        else {
            docImage = [UIImage imageWithCGImage:iref];
            documentName = [imageRep filename];
        }
    };
    // get the asset library and fetch the asset based on the ref url (pass in block above)
    ALAssetsLibrary *imageAsset = [[ALAssetsLibrary alloc] init];
    [imageAsset assetForURL:resourceURL resultBlock:resultblock failureBlock:nil];

现在我希望能够在此 ViewController 的其他地方使用这两个变量(documentName 和 docImage)(例如,如果有人想在保存文档之前更改文档的名称,我希望能够恢复到默认名称),但我似乎无法弄清楚我需要做什么,以便以后可以使用这些变量。不知道这是否有意义,所以如果我需要澄清其他任何事情,请告诉我。

【问题讨论】:

    标签: uiimagepickercontroller alassetslibrary


    【解决方案1】:

    好的,所以我发现问题不在于代码,而在于我如何使用它的逻辑。我试图在选择图像后显示的模态视图上执行此操作,而不是仅在 ImagePicker 屏幕中执行此操作,然后在结果块代码中调用模态窗口。

    【讨论】:

      猜你喜欢
      • 2018-12-19
      • 2021-09-10
      • 1970-01-01
      • 1970-01-01
      • 2022-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多