In-depth analysis of iPhone development animation transition process

Source: Internet
Author: User

In-depth analysisIPhone animatedThe ferry process mainly explainsIphoneUnder developmentExcessive Animation.

1: first obtain the current graphic context:

 
 
  1. CGContextRef context = UIGraphicsGetCurrentContext(); 

2: set some animation attributes to start the animation:

 
 
  1. [UIView beginAnimations:nil context:context];  
  2. [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];  
  3. [UIView setAnimationDuration:1.0]; 

3: set the final state of the object you want to overwrite.

 
 
  1. [big setFrame:SMALLRECT];  
  2. [big setAlpha:0.5];  
  3. [little setFrame:BIGRECT];  
  4. [little setAlpha:1.0]; 

4: Finally, submit the animation so that an animation will be automatically generated.

 
 
  1. [UIView commitAnimations]; 

Among them, setAnimationCurve is the way to set the animation, which has the following centralized method:

 
 
  1. UIViewAnimationCurveEaseInOut // The animation effect is slow at the start and end times.
  2. UIViewAnimationCurveEaseIn // The animation starts slowly.
  3. UIViewAnimationCurveEaseOut // The animation ends slowly.
  4. UIViewAnimationCurveLinear // smooth animation effect

SetAnimationDuration is used to set the animation duration.

Below is an excessive animation between two uiviews.

 
 
  1.        // Start Animation Block  
  2. //CGContextRef context = UIGraphicsGetCurrentContext();  
  3. CGContextRef context = nil;  
  4. [UIView beginAnimations:nil context:context];  
  5. [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:[self superview] cache:YES];  
  6. [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];  
  7. [UIView setAnimationDuration:1.0];  
  8. // Animations  
  9. [[self superview] exchangeSubviewAtIndex:0 withSubviewAtIndex:1];  
  10. // Commit Animation Block  
  11. [UIView commitAnimations]; 

Excessive page interaction mainly relies on the UIView setAnimationTransition: forView: cache: method and exchangeSubviewAtIndex: withSubviewAtIndex:
The former uses the UIView static method to set excessive animation types, and the latter implements real excessive functions. There are five types:

 
 
  1. typedef enum {  
  2.     UIViewAnimationTransitionNone,  
  3.     UIViewAnimationTransitionFlipFromLeft,  
  4.     UIViewAnimationTransitionFlipFromRight,  
  5.     UIViewAnimationTransitionCurlUp,  
  6.     UIViewAnimationTransitionCurlDown,  
  7. } UIViewAnimationTransition; 

In addition to this simple animation method, there is also a kind of over-animation using QuartzCore. the difference is that this excessive animation acts on the layer. In other words, the animation is directly used for the entire UIView, instead of the UIView animation, it can act on the part or itself of the UIView. when UIView functions and itself, it is actually equivalent to layer animation.

 
 
  1. CATransition *animation = [CATransition animation];  
  2. [animation setDelegate:self];  
  3. [animation setDuration:1.0f];  
  4. [animation setTimingFunction:UIViewAnimationCurveEaseInOut];  
  5. [animation setType: kCATransitionMoveIn];  
  6. [animation setSubtype: kCATransitionFromBottom];  
  7. [[self superview] exchangeSubviewAtIndex:0 withSubviewAtIndex:1];  
  8. [[[self superview] layer] addAnimation:animation forKey:@"transitionViewAnimation"];  

SetDuration: the animation effect is the same as that in UIView. setTimingFunction: Specifies the animation type, which is the same as that of UIView, for example, constant speed animation and quick start and end. setType: Specifies the animation type. He has: kCATransitionFade (light-in replenishment animation) kCATransitionMoveIn (feed animation from one way) kCATransitionPush (push method to replenish animation) kCATransitionReveal (one method of trying to show another method) can be used in addition to the first method (Fade-in and fade-out: to define the direction of the animation (because these animations are directly used for layers, it is equivalent to only trying to switch ). there are four animation directions: kCATransitionFromRightkCATransitionFromLeftkCATransitionFromTopkCATransitionFromBotto

Summary: in-depth analysisIPhone development animation transitionThe process has been introduced. I hope this article will help you!

Related Article

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.