iOS development UI article----UI Basics Tom Cat Animation

Source: Internet
Author: User

#import "ViewController.h" @interface Viewcontroller () @property (weak, nonatomic) Iboutlet Uiimageview *imageview;// Definition dictionary read plist file @property (nonatomic, strong) nsdictionary *imagecountdict; @end @implementation viewcontroller//lazy Loading, Override Get Method-(Nsdictionary *) imagecountdict {if (nil = = _imagecountdict) {//Get plist path NSString *path = [[NSBundle m]        Ainbundle] pathforresource:@ "Tom" oftype:@ "Plist"];      Read data in plist _imagecountdict = [Nsdictionary Dictionarywithcontentsoffile:path]; } return _imagecountdict;}  -(void) viewdidload {[Super viewdidload]; Do any additional setup after loading the view, typically from a nib.}  Click on the Head button-(ibaction) Didclickknock: (ID) Sender {[Self startanimationwith:@ "knockout"];  }//Click to drink Milk-(ibaction) Didclickdrink: (ID) Sender {[Self startanimationwith:@ "drink"];    }//Click Fart-(ibaction) Didclickfart: (ID) Sender {[Self startanimationwith:@ "fart"]; }//the same code into a method, the difference becomes the parameter-(void) Startanimationwith: (NSString *) ImageName {//ThroughThe key in the dictionary obtains value, which is the number of the corresponding image nsstring *countstring = [Self.imagecountdict objectforkey:imagename];      Convert to Nsinteger nsinteger count = countstring.integervalue;  Determines whether the frame animation is being executed, and if it is executing, return, that is, the subsequent code will no longer execute the IF (self.imageView.isAnimating) {return; }//1.    An array is required to perform the frame animation (the array elements are image objects) Nsmutablearray *imagearray = [Nsmutablearray array]; Add picture for (int i = 0; i < count; i++) {//Stitching image name NSString *tempimagename = [NSString stringwithformat:@ "%        @_%02d.jpg ", Imagename,i]; Instantiate image Object//If using imagenamed: This method instantiates a picture, it caches the instanced picture, and if it is used again, it will not be re-instantiated//UIImage *image = [UIImage Imagena        Med:imagenmae];          NSString *path = [[NSBundle mainbundle] Pathforresource:tempimagename Oftype:nil];        In this way to load the picture, there will be no cache UIImage *image = [UIImage Imagewithcontentsoffile:path];  Add to Array [Imagearray addobject:image];    }//Assign the array filled with the image object to ImageView self.imageView.animationImages = Imagearray; 2. Interval of Time Self.imagevieW.animationduration = 3; 3.    Number of repetitions Self.imageView.animationRepeatCount = 1; 4.    Start animation [Self.imageview startanimating]; Free memory//[Self.imageview Performselector: @selector (setanimationimages:) Withobject:nil AfterDelay:self.imageView . animationduration + 1];}

iOS development UI article----UI Basics Tom Cat Animation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.