CAKeyframeAnimation设置path后想在delegate里取最后的值,好像不太容易,values和path貌似二者只能取其一,就换values
values是NSArray类型,值是NSValue或者NSNumber,看设置时候是什么
NSValue转其他值:
比如CGPoint:
NSValue *value = (NSValue *)array[array.count -1];
CGPoint point = [value CGPointValue];
NSNumber就直接转了
还有个就是fillMode的问题,调用
-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
这个delegate的方法让layer保留最后的状态值,不设置fillMode会有个卡顿的现象所以,比如要设置为最后状态
group.fillMode = kCAFillModeBackwards;
在一个就是CABasicAnimation经常用的
animation.keyPath =@"transform.rotation";
写成
animation.keyPath =@"transform";
然后toValue设置为CATransform也行,不过比如旋转就不能超过360度
这个叫做Virtual Properties
不同字体是从我以前笔记复制粘贴的哈
transform.rotation属性值并不存在,因为CATransform3D不是一个对象。transform.rotation就是一个Virtual Property。
我知道的有两个 rotation和scale
delegate的调用用到了Property Animation,property animation并不能直接作用于view,只能作用于layer。view.layer也是无效的
-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
if([anim isKindOfClass:[CAAnimationGroup class]]){
for(CAAnimation *animation in ((CAAnimationGroup *)anim).animations){
if([animation isKindOfClass:[CAKeyframeAnimation class]]){
[CATransaction begin];
[CATransaction setDisableActions:YES];
NSArray *array = ((CAKeyframeAnimation *)animation).values;
NSValue *value = (NSValue *)array[array.count - 1];
CGPoint point = [value CGPointValue];
colorLayer.position = point;
[CATransaction commit];
}
if([animation isKindOfClass:[CABasicAnimation class]]){
[CATransaction begin];
[CATransaction setDisableActions:YES];
NSNumber *angleValue = ((CABasicAnimation *)animation).byValue;
colorLayer.transform = CATransform3DMakeRotation([angleValue floatValue], 0, 0, 1);
[CATransaction commit];
}
}
}
}
例1:一个边向前边旋转的动画,其实不是用螺旋前进的UIBezierPath作为path,然后rotationAuto,因为我画不出这样的巴塞尔曲线也没能取出最后的位置进行保存
实现的方式是直线前进,边前进边设置Basic animation的keyPath =@"transform.rotation";byValue = @(某某角度);