how to show ios photo library gif on uiimageview

815 Views Asked by At

i have implemented image picker 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];
}

i am using UIImageView+PlayGIF category to show gif images (loader in my app) from main resource bundle successfully.Some thing like:

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;

Questions: So how can i export photo library gif to document directory as (whatevername.gif), and use above category to show gif.

Or can i get direct nsdata from photolibrary and use above category to show gif.(i prefer this).

I have not tried with UIWebView, can i show gif on UIWebView.

Thanks

1

There are 1 best solutions below

5
Kirit Modi On

set property of imageView.

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

Download the Class of GIF imageLoad with UIImageView

GIFImageLoad

Now load Data from NSBundle.

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

Load image with animatedImageWithAnimatedGIFData as below.

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

OR

Load image with URL animatedImageWithAnimatedGIFURL as below.

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

OR

Load image with GIFURL animatedImageWithAnimatedGIFURL as below.

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