OStack程序员社区-中国程序员成长平台

标题: ios - 如何在ios中加载gif图像并控制它? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 10:58
标题: ios - 如何在ios中加载gif图像并控制它?

在我的应用程序中,我想在我的 View 中加载 gif 图像并控制停止和继续动画。 when i click pause button application should stop animating and when again click start animating



Best Answer-推荐答案


请遵循以下可能对您有所帮助的教程。 http://anand3777.blogspot.in/2014/07/gif-image-loading.html

第 1 步:

   Download library from below url and add it on your project.

https://drive.google.com/folderview?id=0B5JC34Lt79ctamtOVTV6SHhzOVU&usp=sharing

第 2 步:

  Import the file on your "viewController.h" like below.
  //gifImage//
  #import "SCGIFImageView.h"
 //gifImage//

第 3 步:

    Create object like given below on your "viewController.h".
    //gifImage//
    IBOutlet SCGIFImageView* _gifImageView;
    IBOutlet UIButton* _button;
    //gifImage//

第 4 步:

   Create ibaction on your "viewController".
   //gifImage//
    - (IBAction)controlAnimateid)sender;
   //gifImage//

第 5 步:

   Add the following code were you want to use gif image
  //gifImage//
  //load url gif image
  NSURL *imageURL = [NSURL URLWithString"http://google.co.in/anim.gif"];
  NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
  /*
   //load local gif image
   NSString* filePath = [[NSBundle mainBundle] pathForResource"1.gif" ofType:nil];
   NSData* imageData = [NSData dataWithContentsOfFile:filePath];
 */
  _gifImageView = [[SCGIFImageView alloc] initWithFrame:CGRectMake(225, 70, 75, 75)] ;
 [_gifImageView setData:imageData];
 [self.view addSubview:_gifImageView];
 //gifImage//

第 6 步:

   Add the following code for stop/start animating
  //gifImage//
  - (IBAction)controlAnimateid)sender{
     _gifImageView.animating = !_gifImageView.animating;

     if (_gifImageView.animating) {
         [_button setTitle"ause" forState:UIControlStateNormal];
     } else {
         [_button setTitle"Continue" forState:UIControlStateNormal];
     }
  }
 //gifImage//


[1]: https://drive.google.com/folderview?id=0B5JC34Lt79ctamtOVTV6SHhzOVU&usp=sharing

关于ios - 如何在ios中加载gif图像并控制它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25080760/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4