关于IOS 动画的实现
⾸先IOS⾥⾯有许多⾃⼰⾃带的动画 ⽐如present push ⼀个界⾯都会有动画,在项⽬开发中我们常⽤的动画⼀般是以下:
[UIView animateWithDuration:0.5animations:^{
// 执⾏的动画⽐如空间的坐标颜⾊变化
} completion:^(BOOL finished) {
// 完成之后需要处理的
}];
四氧化锰CGAffineTransformMakeScale(, );
或者对于 UIScrollView 滑动的时候根据其代理函数 -(void)scrollViewDidScroll:(UIScrollView *)scrollView{
CGFloat tOffset.x;
// 根据 scrollView的位移改变某些控件的颜⾊左边透明度
}
// 值得注意的是这个函数是按照某个⼩时间段执⾏的是隔⼀段时间执⾏⼀次这意味着如果滑动过快会出现⼀些不⾃然地地⽅但是也可以弥补的
然后接下来就说⼀下IOS的核⼼动画。
所有的核⼼动画都是继承于CAAnimation,还有其它的继承关系如下:
@interface CAPropertyAnimation : CAAnimation
@interface CABasicAnimation : CAPropertyAnimation
@interface CAKeyframeAnimation : CAPropertyAnimation
@interface CASpringAnimation : CABasicAnimation
合成氨变换工段@interface CATransition : CAAnimation
@interface CAAnimationGroup : CAAnimation
总共是CAAnimation CAPropertyAnimation CABasicAnimation CAKeyframeAnimation CASpringAnimation CATransition CAAnimationGroup ⼋个类。
手动注油器(1)能⽤的动画类只有4个⼦类:CABasicAnimation、CAKeyframeAnimation、CATransition、CAAnimationGroup
(2)CAMediaTiming是⼀个协议(protocol)。
地下水位监测
CABasicAnimation* fadeAnim = [CABasicAnimation animationWithKeyPath:@"opacity"];
fadeAnim.fromValue = [NSNumber numberWithFloat:1.0];
fadeAnim.duration = 1.0;
[theLayer addAnimation:fadeAnim forKey:@"opacity"];
// Change the actual data value in the layer to the final value.
theLayer.opacity = 0.0;
弯板机其中的KeyPath是CALayer⾥⾯的各种属性。
CAKeyframeAnimation应⽤如下:
CGMutablePathRef thePath =CGPathCreateMutable();
CGPathMoveToPoint(thePath,NULL,74.0,74.0);
CGPathAddCurveToPoint(thePath,NULL,74.0,500.0,
320.0,500.0,
320.0,74.0);
CGPathAddCurveToPoint(thePath,NULL,320.0,500.0,
566.0,500.0,
566.0,74.0);
CAKeyframeAnimation * theAnimation;
// Create the animation object, specifying the position property as the key path.
theAnimation=[CAKeyframeAnimation animationWithKeyPath:@"position"];
// theAnimation.values=@[[NSValue valueWithCGPoint:CGPointMake(0, 100)],[NSValue valueWithCGPoint:CGPointMake(0, 200)], [NSValue valueWithCGPoint:CGPointMake(0, 300)]];
// 或者
// theAnimation.path=thePath;
theAnimation.duration=5.0;
//keyTimes 这个属性的取值范围是0~1
// Add the animation to the layer.
[button.layer addAnimation:theAnimation forKey:@"position"];
//多个动画在⼀起
CAKeyframeAnimation* widthAnim = [CAKeyframeAnimation animationWithKeyPath:@"borderWidth"];
NSArray* widthValues = [NSArray arrayWithObjects:@1.0,@10.0,@5.0,@30.0,@0.5,@15.0,@2.0,@50.0,@0.0,nil];
widthAnim.values = widthValues;
widthAnim.calculationMode =kCAAnimationPaced;
// Animation 2
CAKeyframeAnimation* colorAnim = [CAKeyframeAnimation animationWithKeyPath:@"borderColor"];
NSArray* colorValues = [NSArray arrayWithObjects:(id)[UIColor greenColor].CGColor,
编织袋颗粒
(id)[UIColor redColor].CGColor, (id)[UIColor blueColor].CGColor, nil];
colorAnim.values = colorValues;
colorAnim.calculationMode =kCAAnimationPaced;
// Animation group
CAAnimationGroup* group = [CAAnimationGroup animation];
group.animations = [NSArray arrayWithObjects:colorAnim, widthAnim,nil];
group.duration = 5.0;
[button.layer addAnimation:group forKey:@"BorderChanges"];
CATransition是CAAnimation的⼦类,⽤于做转场动画,能够为层提供移出屏幕和移⼊屏幕的动画效果。iOS⽐Mac OS X的转场动画效果少⼀点. UINavigationController就是通过CATransition实现了将控制器的视图推⼊屏幕的动画效果.
属性解析:
type:动画过渡类型
subtype:动画过渡⽅向
startProgress:动画起点(在整体动画的百分⽐)
endProgress:动画终点(在整体动画的百分⽐)