IOS animations include attribute animation and transition animation. Before ios4.0
Property Animation
The content and settings are mainly placed in square brackets:
[UIView beginAnimations: @ move context: @ aa];
Set the animation content and attributes in the intermediate part.
[UIView commitAnimations];
The Code is as follows:
[UIView beginAnimations: @ move context: @ aa]; [UIView setAnimationDuration: 1]; // sets the animation time CGPoint point = self. view1.center; // [UIView setAnimationDelegate: self]; // sets the proxy [UIView setAnimationWillStartSelector: @ selector (startAnimation :)]; // before the animation starts, [UIView setAnimationDidStopSelector: @ selector (stopAnition :)]; // After the animation ends // [UIView setAnimationRepeatAutoreverses: YES]; self. view1.center = CGPointMake (point. x + 1, point. y); // self. view1.backgroundColor = [UIColor orangeColor]; [UIView commitAnimations];
You can set the attributes of the property Animation:
The following properties of the UIView class are animatable:
@ Property frame
@ Property bounds
@ Property center
@ Property transform
@ Property alpha
@ Property backgroundColor
@ Property contentStretch
Transition Animation:
[UIView beginAnimations:@move context:@text]; [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.View3 cache:YES]; [UIView commitAnimations];
Attributes that can be set:
Typedef NS_ENUM (NSInteger, UIViewAnimationTransition ){
UIViewAnimationTransitionNone,
UIViewAnimationTransitionFlipFromLeft,
UIViewAnimationTransitionFlipFromRight,
UIViewAnimationTransitionCurlUp,
UIViewAnimationTransitionCurlDown,
};
After 4.0, change it to call block.
Animating Views with Block Objects
// Property Animation
+ AnimateWithDuration: delay: options: animations: completion:
+ AnimateWithDuration: animations: completion:
+ AnimateWithDuration: animations:
// Transition Animation
+ TransitionWithView: duration: options: animations: completion:
+ TransitionFromView: toView: duration: options: completion:
// Key Frame Animation
+ AnimateKeyframesWithDuration: delay: options: animations: completion:
+ AddKeyframeWithRelativeStartTime: relativeDuration: animations:
// System Animation
+ Define msystemanimation: onViews: options: animations: completion:
// Unknown. It is also a test
+ AnimateWithDuration: delay: usingSpringWithDamping: initialSpringVelocity: options: animations: completion:
+ Repeated mwithoutanimation:
CAAnimation Animation
The Code is as follows.
// CABasicAnimation animation CABasicAnimation * baseAnimation = [CABasicAnimation animationWithKeyPath: @ center]; baseAnimation. fromValue = [NSValue valueWithCGRect: CGRectMake (0, 0, 0)]; baseAnimation. fromValue = [NSValue valueWithCGPoint: CGPointMake (400,100)]; baseAnimation. duration = 3; [self. view2.layer addAnimation: baseAnimation forKey: @ baseAnimation]; // CAKeyframeAnimation animation CAKeyframeAnimation * keyAnimation = [CAKeyframeAnimation animationWithKeyPath: @ position]; keyAnimation. values = [NSArray arrayWithObjects: [NSValue valueWithCGPoint: CGPointMake (self. view2.center. x + 5, self. view2.center. y)], [NSValue valueWithCGPoint: CGPointMake (self. view2.center. x, self. view2.center. y)], [NSValue valueWithCGPoint: CGPointMake (self. view2.center. x-5, self. view2.center. y)], [NSValue valueWithCGPoint: CGPointMake (self. view2.center. x, self. view2.center. y)], [NSValue valueWithCGPoint: CGPointMake (self. view2.center. x + 5, self. view2.center. y)], [NSValue valueWithCGPoint: CGPointMake (self. view2.center. x, self. view2.center. y)], nil]; keyAnimation. keyTimes = @ [NSNumber numberWithFloat :. 1], [NSNumber numberWithFloat :. 2], [NSNumber numberWithFloat :. 3], [NSNumber numberWithFloat :. 4], [NSNumber numberWithFloat :. 5], [NSNumber numberWithFloat: 1]; // set the time, percentage keyAnimation. calculationMode = kCAAnimationDiscrete; [self. view2.layer addAnimation: keyAnimation forKey: @ position]; // CATransition animation CATransition * transiton = [CATransition animation]; transiton. startProgress = 0; transiton. endProgress = 1.0; transiton. duration = 3; transiton. type = kCATransitionReveal; // display different animations based on different values. subtype = kCATransitionFromRight; [self. view. layer addAnimation: transiton forKey: @ transtion];