小编yip*_*ipe的帖子

如何使用CAKeyframeAnimation为CATransform3D设置动画?

我已经使用CAKeyframeAnimations为图层transform.rotationtransform.translation.x属性设置动画,但是我无法transform隐式地为该属性设置动画.我有一个必须在两个状态之间设置动画的图层,而CABasicAnimation的默认插值完全不正确,并且不遵循我想要的路径.CAKeyframeAnimation救援,或者我认为.任何transform使用CAKeyframeAnimation 进行动画处理的尝试都会导致视图在其他动画运行时立即捕捉到最终转换.如果我删除下面函数的前半部分并让我的"转换"事件使用底部的CABasicAnimation,它会动画很好 - 尽管沿途有不正确的插值变换.

我的图层委托实现了以下内容:

- (id <CAAction>) actionForLayer:(CALayer *)layer forKey:(NSString *)event
{    
    if ([event isEqualToString:@"transform"])
    {
        CGSize startSize = ((CALayer *)self.layer.presentationLayer).bounds.size;
        CGSize endSize = self.layer.bounds.size;

        CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:event];
        animation.duration = 0.25;

        NSMutableArray *values = [NSMutableArray array];

        int stepCount = 10;
        for (int i = 0; i < stepCount; i++)
        {
            CGFloat p = i / (float)(stepCount - 1);
            CGSize size = [self interpolateBetweenSize:startSize andSize:endSize percentage:p];
            CATransform3D transform = [self …
Run Code Online (Sandbox Code Playgroud)

iphone core-animation objective-c ios

13
推荐指数
1
解决办法
3201
查看次数

标签 统计

core-animation ×1

ios ×1

iphone ×1

objective-c ×1