IPhone animation implementation methods

Source: Internet
Author: User

IPhone AnimationThe two implementation methods are described in this article.IphonePrettyAnimationThere are two main effects:UIViewLevel, one is to useCATransitionLower-level control,

The first type isUIView,UIViewMethod may also be used in the lower layerCATransitionIt is encapsulated and can only be used for some simple and common effects. Here we will write a common sample code for your reference.

 
 
  1. [UIView beginAnimations: @ "Curl" context: nil]; // starts the animation.
  2. [UIView setAnimationDuration: 0.75];
  3. [UIView setAnimationDelegate: self];
  4. [UIView setAnimationTransition: UIViewAnimationTransitionCurlUp forView: myview cache: YES];
  5. [Myview removeFromSuperview];
  6. [UIView commitAnimations];

The second method is relatively complicated, but if you want to better control it, you can use this method. For the basic usage method, refer to the following example:

 
 
  1. CATransition *animation = [CATransition animation];   
  2. [animation setDuration:1.25f];  
  3.  [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];   
  4.  [animation setType:kCATransitionReveal];   
  5.  [animation setSubtype: kCATransitionFromBottom];   
  6.  [self.view.layer addAnimation:animation forKey:@"Reveal"];  

The setType and setSubtype combinations are used here, which is relatively safe, because their parameters are defined in the official API. Their parameter descriptions can be referred to below:

SetType: four types can be returned:

 
 
  1. KCATransitionFade fade out
  2. KCATransitionMoveIn overwrites the source Image
  3. KCATransitionPush
  4. The bottom of kCATransitionReveal is shown

SetSubtype: there can also be four types:

 
 
  1. KCATransitionFromRight;
  2. KCATransitionFromLeft (default)
  3. KCATransitionFromTop;
  4. KCATransitionFromBottom

There is also a way to set the animation type, without setSubtype or setType.

 
 
  1. [animation setType:@"suckEffect"];  

SuckEffect here is the name of the effect. The following effects can be used:

PageCurl flip one page up pageUnCurl flip one page down rippleEffect drip effect suckEffect shrink effect, such as a piece of cloth is extracted from the cube effect oglFlip flip up and down effect
Finally, a common code is provided for your reference.

 
 
  1. // Curl the image up or down CATransition *animation = [CATransition animation];  
  2.  [animation setDuration:0.35];   
  3. [animation setTimingFunction:UIViewAnimationCurveEaseInOut];  
  4.  if (!curled){  
  5.   //animation.type = @"mapCurl";  
  6.   animation.type = @"pageCurl";   
  7.   animation.fillMode = kCAFillModeForwards;  
  8.    animation.endProgress = 0.99;   
  9. } else {  
  10.   //animation.type = @"mapUnCurl";   
  11. animation.type = @"pageUnCurl";   
  12. animation.fillMode = kCAFillModeBackwards;   
  13. animation.startProgress = 0.01;  
  14.  }   
  15.  [animation setRemovedOnCompletion:NO];   
  16.  [view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];  
  17.   [view addAnimation:animation forKey"pageCurlAnimation"];  
  18.    // Disable user interaction where necessary if (!curled) {   }   
  19. else {   
  20.   }  
  21.    curled = !curled;  

Summary:IPhone AnimationTwo implementationsUIViewAndCATransitionThe content of this method 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.