Several methods of animation programming in iOS development and ios development
Several methods of animation programming in iOS development
There are five animation summaries in IOS: UIView <block>, CAAnimation <CABasicAnimation, CATransition, CAKeyframeAnimation>, NSTimer
Here I will summarize these five methods. In fact, animation programming in iOS development will change here, so it is not difficult to understand these animation programming.
I. general way of UIView Animation
- Typedef enum {
- UIViewAnimationTransitionNone, // normal status
- UIViewAnimationTransitionFlipFromLeft, // flip from left to right
- UIViewAnimationTransitionFlipFromRight, // flip from right to left
- UIViewAnimationTransitionCurlUp, // flip up
- UIViewAnimationTransitionCurlDown, // flip down
- } UIViewAnimationTransition;
- Typedef enum {
- UIViewAnimationCurveEaseInOut,
- UIViewAnimationCurveEaseIn,
- UIViewAnimationCurveEaseOut,
- UIViewAnimationCurveLinear
- } UIViewAnimationCurve;
Here I have implemented a Custom Animation Method for ease of use. You only need to call it to implement good functions.
Method implementation
-(Void) UIViewAnimation :( UIView *) view frame :( CGRect) frame type :( int) type alpha :( float) alpha duration :( float) duration
{
// Implement the corresponding parameters in the method. When calling this method, you only need to enter the required parameters in the method to call this method well and implement the desired function!
[UIView beginAnimations: nil context: nil];
[UIView setAnimationDuration: duration];
[UIView setAnimationCurve: type];
[UIView setAnimationDelegate: self];
View. alpha = alpha;
View. frame = frame;
[UIView commitAnimations];
}
Call Method
[Self UIViewAnimation: downView frame: CGRectMake (0, height, 320, 58) type: UIViewAnimationCurveEaseOut alpha: 1 duration: 0.3];
Block Method
More advanced block animation (Next) embedded
-(Void) changeUIView {[UIView animateWithDuration: 2 delay: 0 options: UIViewAnimationOptionCurveEaseOut animations: ^ (void) {moveView. alpha = 0.0;} completion: ^ (BOOL finished) {[UIView animateWithDuration: 1 delay: 1.0 options: available | refreshing animations: ^ (void) {[UIView setAnimationRepeatCount: 2.5]; moveView. alpha = 1.0 ;}completion: ^ (BOOL finished) {}] ;}];}
Ii. CAAnimation
You need to add libraries and header files.
Caanimation has multiple subclasses
CABasicAnimation
CAKeyframeAnimation
CATransition
- /*
- KCATransitionFade;
- KCATransitionMoveIn;
- KCATransitionPush;
- KCATransitionReveal;
- */
- /*
- KCATransitionFromRight;
- KCATransitionFromLeft;
- KCATransitionFromTop;
- KCATransitionFromBottom;
- */
- /*
- Cube
- SuckEffect
- OglFlip flip
- RippleEffect
- PageCurl Paging
- PageUnCurl
- CameraIrisHollowOpen
- CameraIrisHollowClose
- */
Iii. NSTimer
This is a timer to operate the animation, he can combine the above method to achieve the diversity of animation!
}