2016-06-14 4 views
1
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView 
       cellForItemAtIndexPath:(NSIndexPath *)indexPath 

{ 

    [_keyboard.collectionView registerClass:[NibCell class] forCellWithReuseIdentifier:@"Cell"]; 


    static NSString *identifier = @"Cell"; 

    NibCell *cell = [self.keyboard.collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath]; 

    UIImageView * rampageGifImage = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, cell.frame.size.width, cell.frame.size.height)]; 


    [rampageGifImage setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@.gif",[rampageGif objectAtIndex:indexPath.row]]]]; 


    [cell.layer setCornerRadius:4]; 

    [cell addSubview:rampageGifImage]; 

    return cell; 
} 
+0

Sie das GIF-Format auf einer nativen Ansicht nicht haben können. Verwenden Sie WebView für dieses oder wenn Sie es wirklich zeigen möchten, benutzen Sie eine Bibliothek, die die Bilder bricht und sie wiederbelebt. https://github.com/Flipboard/FLAnimatedImage – Joshua

Antwort

1

Sie können Gif Image von SDWebImage von Github in Ihrem Projekt verwenden.

Versuchen Sie, wie diese,

#import "UIImage+GIF.h" 

_imageViewAnimatedGif.image= [UIImage sd_animatedGIFNamed:@"YOURGIF_IMAGE"]; 

Hope this Ihnen helfen.

+0

Besuchen Sie diesen Link zum besseren Verständnis: https://github.com/rs/SDWebImage/blob/master/SDWebImage/UIImage%2BGIF.m –

+0

Wie auch immer, ich habe FLAnimatedImage aus github .. aber das Problem ist, App ist crashing becuz von überschüssige Menge an Speicherverbrauch ... Können Sie mir mit diesem Problem helfen, Danke – Santosh

+0

Sie sollten zumindest versuchen mit SDWebImage .. –

1

Try it. It is small category that could loads animated GIF. Also, jpg, png, etc..

#import "ViewController.h" 
#import "UIImage+Gif.h" 

@interface ViewController() 
@property (weak, nonatomic) IBOutlet UIImageView *imageView1; 
@property (weak, nonatomic) IBOutlet UIImageView *imageView2; 
@end 

@implementation ViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    // Usage 1 : gifWidthData 
    NSData *data = [NSData dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"f1" withExtension:@"gif"]]; 

    self.imageView1.image = [UIImage gifWithData:data]; 

    // Usage 2 : gifWidthURL 
    NSURL *url = [[NSBundle mainBundle] URLForResource:@"f2" withExtension:@"gif"]; 
    self.imageView2.image = [UIImage gifWithURL:url]; 
}