CABasicAnimation无法在iOS7中运行

时间:2014-01-22 17:18:02

标签: cabasicanimation

我正在尝试向视图添加微调器并使用以下代码为其设置动画。它在iOS 6中运行得非常好,但在iOS 7上没有。旋转器不旋转

这是使用微调器创建图层的函数

- (CALayer *)spinnerLayer
{
CALayer *result = nil;

UIImage *spinnerImage = [UIImage imageNamed:@"spin.png"];
if (spinnerImage != nil)
{
    CGSize size = [spinnerImage size];
    CALayer *layer = [[CALayer alloc] init];
    if (layer != nil)
    {
        [layer setFrame:CGRectMake(0.0, 0.0, size.width, size.height)];

        [layer setContents:(id)[spinnerImage CGImage]];

        CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
        if (anim != nil)
        {
            [anim setToValue:@(M_PI * 2.0)];

            [anim setRepeatCount:INFINITY];
            [anim setDuration:1.0];
            [anim setFillMode:kCAFillModeBoth];

            [layer addAnimation:anim forKey:@"Rotation"];
        }

        result = [[layer retain] autorelease];

        [layer release];
    }
}

return result;

}

1 个答案:

答案 0 :(得分:8)

通过仅在显示图像视图的viewcontroller的viewDidAppear中添加动画来修复它。

来自here的有用见解