ios - 如何在 uiimageview 上显示 ios 照片库 gif

标签 ios uiimageview gif alasset alassetlibrary

我已经实现了图像选择器 Controller 委托(delegate):

- (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 吗?

谢谢

最佳答案

设置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];

关于ios - 如何在 uiimageview 上显示 ios 照片库 gif,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31445469/

相关文章:

ios - CGAffineTransformMakeRotation 在 3D 中旋转

ios - viewDidLoad 中的动画

android - 如何通过 Intent Android 从外部存储分享 gif 图像?

ios - UIScrollView 框架在 iOS 8 和 iOS 7 上的大小不同

javascript - 如何将 Canvas 动画保存为 gif 或 webm?

java - 可以对 ImageIcons 进行分层吗?

ios - 图像旋转会导致像素丢失吗?(Core Graphics)

iphone - 如果我的 iPhone 应用程序使用 Bonjour,我是否需要与 Apple 签订许可协议(protocol)?

ios - 添加新 child 时出现 dispatch_group_leave 错误

ios - 在 iMessage 应用程序中检查横向/纵向方向(扩展)