Search code examples
iosxcodestartupgif

How to load gif image and control that in ios?


In my application i want load the gif images in my view and also controls stop and continue animating.when i click pause button application should stop animating and when again click start animating


Solution

  • Kindly follow the below tutorial that may help you. http://anand3777.blogspot.in/2014/07/gif-image-loading.html

    Step 1:

       Download library from below url and add it on your project.
    
    https://drive.google.com/folderview?id=0B5JC34Lt79ctamtOVTV6SHhzOVU&usp=sharing
    

    Step 2:

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

    Step 3:

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

    Step 4:

       Create ibaction on your "viewController".
       //gifImage//
        - (IBAction)controlAnimate:(id)sender;
       //gifImage//
    

    Step 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//
    

    Step 6:

       Add the following code for stop/start animating
      //gifImage//
      - (IBAction)controlAnimate:(id)sender{
         _gifImageView.animating = !_gifImageView.animating;
    
         if (_gifImageView.animating) {
             [_button setTitle:@"Pause" forState:UIControlStateNormal];
         } else {
             [_button setTitle:@"Continue" forState:UIControlStateNormal];
         }
      }
     //gifImage//
    
    
    [1]: https://drive.google.com/folderview?id=0B5JC34Lt79ctamtOVTV6SHhzOVU&usp=sharing