Core Animations一些常用常忘的吧

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 = @(某某角度);



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值