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.
- [UIView beginAnimations: @ "Curl" context: nil]; // starts the animation.
- [UIView setAnimationDuration: 0.75];
- [UIView setAnimationDelegate: self];
- [UIView setAnimationTransition: UIViewAnimationTransitionCurlUp forView: myview cache: YES];
- [Myview removeFromSuperview];
- [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:
- CATransition *animation = [CATransition animation];
- [animation setDuration:1.25f];
- [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
- [animation setType:kCATransitionReveal];
- [animation setSubtype: kCATransitionFromBottom];
- [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:
- KCATransitionFade fade out
- KCATransitionMoveIn overwrites the source Image
- KCATransitionPush
- The bottom of kCATransitionReveal is shown
SetSubtype: there can also be four types:
- KCATransitionFromRight;
- KCATransitionFromLeft (default)
- KCATransitionFromTop;
- KCATransitionFromBottom
There is also a way to set the animation type, without setSubtype or setType.
- [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.
- // Curl the image up or down CATransition *animation = [CATransition animation];
- [animation setDuration:0.35];
- [animation setTimingFunction:UIViewAnimationCurveEaseInOut];
- if (!curled){
- //animation.type = @"mapCurl";
- animation.type = @"pageCurl";
- animation.fillMode = kCAFillModeForwards;
- animation.endProgress = 0.99;
- } else {
- //animation.type = @"mapUnCurl";
- animation.type = @"pageUnCurl";
- animation.fillMode = kCAFillModeBackwards;
- animation.startProgress = 0.01;
- }
- [animation setRemovedOnCompletion:NO];
- [view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
- [view addAnimation:animation forKey"pageCurlAnimation"];
- // Disable user interaction where necessary if (!curled) { }
- else {
- }
- curled = !curled;
Summary:IPhone AnimationTwo implementationsUIViewAndCATransitionThe content of this method has been introduced. I hope this article will help you!