2016-06-14 7 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

あなたはネイティブのビュー上のGIFを持つことができません。このためにWebViewを使用するか、実際に画像を表示して再表示するライブラリを使用したい場合は、それを再表示します。 https://github.com/Flipboard/FLAnimatedImage – Joshua

答えて

1

Gif ImageはGithubのSDWebImageをプロジェクトに追加することで使用できます。

これはあなたを助けることを願って、このよう

#import "UIImage+GIF.h" 

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

を試してみてください。

+0

このリンクにアクセスして理解を深める:https://github.com/rs/SDWebImage/blob/master/SDWebImage/UIImage%2BGIF.m –

+0

とにかく、私はFLAnimatedImageをgithub ..しかし、問題は、アプリケーションがメモリ使用量の超過量のbecuzをクラッシュしています...あなたはこの問題でお手伝いできますか、ありがとう – Santosh

+0

あなたは少なくとも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]; 
} 
関連する問題