In-depth analysisIPhone animatedThe ferry process mainly explainsIphoneUnder developmentExcessive Animation.
1: first obtain the current graphic context:
- CGContextRef context = UIGraphicsGetCurrentContext();
2: set some animation attributes to start the animation:
- [UIView beginAnimations:nil context:context];
- [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
- [UIView setAnimationDuration:1.0];
3: set the final state of the object you want to overwrite.
- [big setFrame:SMALLRECT];
- [big setAlpha:0.5];
- [little setFrame:BIGRECT];
- [little setAlpha:1.0];
4: Finally, submit the animation so that an animation will be automatically generated.
- [UIView commitAnimations];
Among them, setAnimationCurve is the way to set the animation, which has the following centralized method:
- UIViewAnimationCurveEaseInOut // The animation effect is slow at the start and end times.
- UIViewAnimationCurveEaseIn // The animation starts slowly.
- UIViewAnimationCurveEaseOut // The animation ends slowly.
- UIViewAnimationCurveLinear // smooth animation effect
SetAnimationDuration is used to set the animation duration.
Below is an excessive animation between two uiviews.
- // Start Animation Block
- //CGContextRef context = UIGraphicsGetCurrentContext();
- CGContextRef context = nil;
- [UIView beginAnimations:nil context:context];
- [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:[self superview] cache:YES];
- [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
- [UIView setAnimationDuration:1.0];
- // Animations
- [[self superview] exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
- // Commit Animation Block
- [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:
- typedef enum {
- UIViewAnimationTransitionNone,
- UIViewAnimationTransitionFlipFromLeft,
- UIViewAnimationTransitionFlipFromRight,
- UIViewAnimationTransitionCurlUp,
- UIViewAnimationTransitionCurlDown,
- } 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.
- CATransition *animation = [CATransition animation];
- [animation setDelegate:self];
- [animation setDuration:1.0f];
- [animation setTimingFunction:UIViewAnimationCurveEaseInOut];
- [animation setType: kCATransitionMoveIn];
- [animation setSubtype: kCATransitionFromBottom];
- [[self superview] exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
- [[[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!