【问题标题】:how to show ios photo library gif on uiimageview如何在uiimageview上显示ios照片库gif
【发布时间】:2015-10-05 09:11:40
【问题描述】:

我已经实现了图像选择器控制器委托:

- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = [info valueForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:@"public.image"]) {
    UIImage *anImage = [info objectForKey:UIImagePickerControllerOriginalImage];
//i know i can get image name from info key.
    if(self.block) self.block(YES, anImage, nil);
}
[picker dismissViewControllerAnimated:YES completion:nil];
}

我正在使用 UIImageView+PlayGIF 类别成功地显示 主资源包中的 gif 图像(我的应用程序中的加载器)。类似于:

NSData *gifData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"loading_image.gif" ofType:nil]];
CGRect bnd = view.bounds;
loader.gifView = [[YFGIFImageView alloc] initWithFrame:CGRectMake(bnd.size.width/2-60, bnd.size.height/2-70, 120, 120)];
loader.gifView.backgroundColor = [UIColor clearColor];
loader.gifView.gifData = gifData;

问题: 那么如何将照片库 gif 导出为(whatevername.gif)的文档目录,并使用上述类别显示 gif。

或者我可以从照片库中直接获取 nsdata 并使用上述类别来显示 gif。(我更喜欢这个)。

我没有尝试过使用 UIWebView,我可以在 UIWebView 上显示 gif。

谢谢

【问题讨论】:

    标签: ios uiimageview gif alasset alassetlibrary


    【解决方案1】:

    设置 imageView 的属性。

    @property (strong, nonatomic) IBOutlet UIImageView *YFGIFImageView; 
    

    使用UIImageView下载GIF imageLoad类

    GIFImageLoad

    现在从NSBundle 加载数据。

        NSURL *url = [[NSBundle mainBundle] URLForResource:@"loading_image" withExtension:@"gif"];
    

    使用animatedImageWithAnimatedGIFData 加载图像,如下所示。

        self.YFGIFImageView.image = [UIImage animatedImageWithAnimatedGIFData:[NSData dataWithContentsOfURL:url]];
    

    使用 URL animatedImageWithAnimatedGIFURL 加载图像,如下所示。

        self.YFGIFImageView.image = [UIImage animatedImageWithAnimatedGIFURL:url];
    

    使用 GIFURL animatedImageWithAnimatedGIFURL 加载图像,如下所示。

        self.YFGIFImageView.image = [UIImage animatedImageWithAnimatedGIFURL:url];
    

    【讨论】:

    • 非常感谢您的回复(已经在做),但我想使用 pho 库(ALAsset)获取 gifData,并使用 YGF 类别显示数据。请再次阅读我的问题跨度>
    • 嗯,我了解从库中获取 GIF
    • 尝试上面从库中获取 GIF 图片,
    • ALAssetRepresentation *representation = [asset defaultRepresentation]; NSLog(@"%@",[表示网址]);
    猜你喜欢
    • 2017-06-17
    • 1970-01-01
    • 2020-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-26
    • 1970-01-01
    • 2020-08-11
    相关资源
    最近更新 更多