一、UIView自带动画(UIKit框架中)
- frame
(平移 + 缩放) - bounds
(平移 + 缩放) - center
(平移) - transform
(变换【平移 + 缩放 + 旋转】)
- alpha
(透明度) - backgroundColor
(背景色) - contentStretch
(6.0之后已经弃用)
[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration:2.25];
[UIView setAnimationCurve:UIViewAnimationCurveLine
[UIView setAnimationDelegate:self];//一定要设置动画的委托
............... .{改变View属性的代码块}...................
.........
[UIView commitAnimations];
If you want to execute code immediately before or after an animation, you must associate a delegate object and a start or stop selector with your begin/commit animation block. You set your delegate object using the setAnimationDelegate:
class method of UIView
and you set your start and stop selectors using the setAnimationWillStartSelector:
and setAnimationDidStopSelector:
class methods. During the animation, the animation system calls your delegate methods at the appropriate times to give you a chance to perform your code.
The signatures of your animation delegate methods need to be similar to the following:
- (void)animationWillStart:(NSString *)animationID context:(void *)context; |
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context; |
+ (void) setAnimationTransition:(UIViewAnimationTransitio
![IOS <wbr>动画总结](https://img-my.csdn.net/uploads/201301/14/1358154251_1234.png)
![IOS <wbr>动画总结](https://img-my.csdn.net/uploads/201301/14/1358154352_3552.png)
二、使用核心动画(Core Animation)[QuartzCore.framework中]
其中CABasicAnimation和CAKeyframeAnimation是对图层中的不同属性进行动画的。
如果要多整个图层进行动画,则应该使用CATransitionAnimation
如果要使用组合动画,例如要改变图层的大小和透明度,则可以先为每个属性创建一个CABasicAnimation对象,再把他们组合到CAAnimationGroup中,最后把这个组合添加到要进行动画的CALayer中。
(4).使用:CATransition
淡化、推挤、揭开、覆盖
NSString * const kCATransitionFade;
NSString * const kCATransitionMoveIn;
NSString * const kCATransitionPush;
NSString * const kCATransitionReveal;
transition.subtype
NSString * const kCATransitionFromRight;
NSString * const kCATransitionFromLeft;
NSString * const kCATransitionFromTop;
NSString * const kCATransitionFromBottom;
![IOS <wbr>动画总结](https://img-my.csdn.net/uploads/201301/15/1358211158_5255.png)
![IOS <wbr>动画总结](https://img-my.csdn.net/uploads/201301/15/1358211332_1649.png)
私有的类型的动画类型:
立方体、吸收、翻转、波纹、翻页、反翻页、镜头开、镜头关
- animation.type
= @"cube" - animation.type
= @"suckEffect"; - animation.type
= @"oglFlip";//不管subType is "fromLeft" or "fromRight",official只有一种效果 - animation.type
= @"rippleEffect"; - animation.type
= @"pageCurl"; - animation.type
= @"pageUnCurl" - animation.type
= @"cameraIrisHollowOpen "; - animation.type
= @"cameraIrisHollowClose ";
![IOS <wbr>动画总结](https://img-my.csdn.net/uploads/201301/15/1358213093_4460.png)
CATransition的 startProgress endProgress属性
可以控制动画进行的过程,可以让动画停留在某个动画点上,值在0.0到1.0之间。endProgress要大于等于startProgress。
但运行以上代码,又发现问题了,动画结束后设定图层位置,图层会重新从起始位置运动到终点位置,这是因为对于非根图层而言,设置图层的可动画属性会产生隐式动画,当然可以设置动画图层为根图层来解决这个问题,但实际当中是通过关闭隐式动画来解决这个问题。要关闭隐式动画,需要用到动画事务CATransaction,在事务内关闭隐式动画,例如:
- - (void) startBaseAnimation:(CGPoint) location {
- endPoint = location;
- //开启动画事物
- [CATransaction begin];
- //禁用隐式动画
- [CATransaction setDisableActions:YES];
- layer.position = endPoint;
- // 1、创建动画,并且指定位置(position)作为动画属性
- CABasicAnimation *baseAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
- // 2、设置动画属性初始值和结束值
- baseAnimation.fromValue = [NSValue valueWithCGPoint:startPoint];
- baseAnimation.toValue = [NSValue valueWithCGPoint:endPoint];
- // 设置其他动画属性
- baseAnimation.duration = 3.0;
- // 设定代理
- baseAnimation.delegate = self;
- // 存储要设定的目标值
- [baseAnimation setValue:[NSValue valueWithCGPoint:location] forKey:@"BaseAnimationPosition"];
- // 3、添加动画到图层,key相当于给动画命名,可以通过此key来获取该动画
- [layer addAnimation:baseAnimation forKey:@"kBaseAnimation"];
- //提交动画事务
- [CATransaction commit];
- }
http://blog.csdn.net/totogo2010/article/details/8501812
http://www.cnblogs.com/project/archive/2011/09/27/2193556.html