Summary of various types and methods of animation in iOS development

Source: Internet
Author: User

1.UIImage Animation picture Animation

#define FPS 30.0-(void) viewdidload{[Super Viewdidload];    UIImage *image = [UIImage animatedimagenamed:@ "Ship-anim" duration:5*1/fps]; Self.imageView.image = image;}


How the 2.NSTimer timer implements animations

2.1 Basic methods:

 #define  FPS 30.0-  (void) viewdidload{    [super viewDidLoad];   self.count = 0;    self.imageview.alpha = 0;   //use 1/fps to calculate how long each frame takes    [NSTimer  Scheduledtimerwithtimeinterval:1/fps target:self selector: @selector (changealpha:)  userInfo:nil  repeats:yes];} -(void) Changealpha: (nstimer *) timer{   self.count++;   //calculates the alpha value to be modified for each frame    SELF.IMAGEVIEW.ALPHA+=1/(fps*5);    //determines the    //stop timer based on the number of frames that complete the animation    if (self.count==fps*5) {   [timer invalidate];   nslog (@ " .     }} 

 2.2nstimer Animation plane flight

#define  FPS 30.0//  Frame rate #define duration 2.0 //  animation duration-  (void) viewdidload{     [super viewDidLoad];    self.startCenter =  self.imageview.center;    self.count = 0;} -  (ibaction) Start: (uibutton *) sender {    [nstimer  Scheduledtimerwithtimeinterval:1/fps target:self selector: @selector (move:)  userInfo:nil  Repeats:yes];} Each frame to execute the Move method, modify the center point of the picture//constant Speed Animation: Current value  =  Start value + Current frame number * (end value-start value)/(frame rate * Animation duration)-(void) Move: (nstimer *) timer{     self.count++;    CGPoint center =  self.imageview.center;    center.y = self.startcenter.y + self.count* ( 70-SELF.STARTCENTER.Y)/(fps*duration);    self.imageview.center = center;     if (self.count >= fps*duration) {   &NBsp;    [timer invalidate];    }} 

2.3 Variable Speed formula

-(Ibaction) Start: (ID) Sender {[Nstimer scheduledtimerwithtimeinterval:1/fps target:self selector: @selector (move:) Userinfo:nil Repeats:yes];}    Variable speed formula://Current value = Last value + (target value-last value) * Progressive factor-(void) Move: (Nstimer *) timer{cgpoint center = self.imageView.center;    Center.y = center.y+ (70-center.y) *0.08;    Self.imageView.center = center;    if (center.y<=70) {[Timer invalidate]; }}

3.UIView aniamtion

3.1 Basic Methods

-(Ibaction) Start: (ID) Sender {cgpoint Center = self.imageView.center;    CENTER.Y = 70;    [UIView Animatewithduration:3 animations:^{///Here just set the state of the view at the end of the animation to be added self.imageView.center = center; }];}

  3.2 Other methods

-  (void) viewdidload{    [super viewdidload];    //first record the position at the moment , as     //animation at the end of the position     CGRect labelEndFrame =  self.label.frame;    cgrect imageviewendframe = self.imageview.frame;     //set the starting position of the label before animating     CGRect labelStartFrame =  labelendframe;    labelstartframe.origin.x = -labelstartframe.size.width;     self.label.frame = labelStartFrame;    CGRect  imageviewstartframe = imageviewendframe;    imageviewstartframe.origin.y =  self.view.bounds.size.height;    self.imageView.frame =  imageviewstartframe;    //adding animations     [uiview animatewithduration:2  animations:^{        //set the end position of two views that need to be animated         self.label.frame =  labelendframe;        self.imageview.frame =  imageviewendframe;    }];} -  (ibaction) move: (ID) sender {    cgpoint center =  self.imageview.center;    center.y -= 300;     Cgaffinetransform transform = cgaffinetransformmakerotation (M_PI);     [ uiview animatewithduration:3 delay:0 options:uiviewanimationoptioncurveeasein| Uiviewanimationoptionrepeat| uiviewanimationoptionautoreverse animations:^{         self.imageview.center = center;         Self.imageview.transform = transform;    } completion:nil];}





Summary of various types and methods of animation in iOS development

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.