CAAnimation——基本动画,关键帧动画和贝塞尔路径
概述
在做对于图层的动画效果时,往往直接改变属性或者使用隐式动画是不能满足我们的需求的,所以我们就用到了显式动画,CAAnimation。它可以管理重复动画、准确的控制时间和步调,并且能设定图层过渡。当然,所有隐式动画能做到的,显式动画也都能做到。
来看下CAAnimation的继承体系
CABasicAnimation
- (void)demoViewBezierPathAnimation{ UIBezierPath *path = [UIBezierPath bezierPath]; [path moveToPoint:_demoView.center]; //一定要设置 不然底层的CGPathRef找不到起始点,将会崩溃 [path addCurveToPoint:CGPointMake(270, 410) controlPoint1:CGPointMake(0, Screen_Height) controlPoint2:CGPointMake(Screen_Width, 0)]; //以左下角和右上角为控制点 CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; animation.path = path.CGPath; animation.duration = 3.0f; animation.removedOnCompletion = NO; animation.fillMode = kCAFillModeForwards; [_demoView.layer addAnimation:animation forKey:nil];}