多个CALayers动画-填充模式 [英] Multiple CALayers Animation - Fill Mode

查看:48
本文介绍了多个CALayers动画-填充模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将屏幕分成小块,然后为每个块设置动画以执行过渡:

I am separating the screen into small tiles, then animating each tile to perform a transition:

    for (int x=0; x<number_of_x_splits; x++) {

    for (int y=0; y<number_of_y_splits; y++) {

        CGSize splitSize = CGSizeMake(screenBounds.width / number_of_x_splits, screenBounds.height / number_of_y_splits);

        CATransformLayer *transformLayer = [CATransformLayer layer];
        [transformLayer setFrame:CGRectMake(splitSize.width * x, splitSize.height * y, splitSize.width, splitSize.height)];
        [transformLayer setPosition:CGPointMake((splitSize.width * x) + splitSize.width / 2, (splitSize.height * y) + splitSize.height / 2)];

        ... adding some sublayers to transformLayer...

        CABasicAnimation *rotate = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
        [rotate setDuration:5.0];
        [rotate setFromValue:[NSNumber numberWithFloat:0]];
        [rotate setToValue:[NSNumber numberWithFloat:M_PI]];
        [rotate setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
        [rotate setTimeOffset:(1 / (number_of_x_splits + number_of_y_splits)) * (x+y)];
        [rotate setFillMode:kCAFillModeForwards];
        [rotate setRemovedOnCompletion:NO];
        [transformLayer addAnimation:rotate forKey:@"transform.rotation.y"];

    }
}

问题是只有最后一个链中的CALayer保持最终位置。
我也尝试设置CALayer最终转换值:

The problem is that only the last CALayer in the chain remains at final position. I have also tried to set the CALayer final transform value:

[transformLayer setTransform:CATransform3DMakeRotation(M_PI, 0, 1, 0)];

我想这与在循环中创建另一个CALayer实例有关重置前一个的属性

I guess it have to do with creating another instance of CALayer in the loop reset the properties of the previous layer.

有人建议如何解决这种情况吗?

Anyone have a suggestion how to remedy the situation?

推荐答案

timeOffset 不是您要使用的属性,它实际上会在动画开始的那一点发生变化,而不是延迟直到它开始。相反,您应该设置动画的 beginTime

timeOffset is not the property you want to use, that actually changes at what point into the animation it will begin and not the delay until it starts. Instead you should set the beginTime of the animation.

请记住开始时间应为 CACurrentMediaTime()+ yourDelay

timeOffset和beginTime之间的差异可以这样表示。我知道我以前看过这个插图,只是找不到。

The difference between timeOffset and beginTime can be illustrated like this. I know I've seen this illustration before, I just couldn't find it.

Normal animation    | 12345678 |
Begin time          |     12345678 |
Time offset         | 5678     |

这篇关于多个CALayers动画-填充模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆