I am trying to add a spinner to the view and animate it using following code. It worked perfectly fine in iOS 6, but doesn't on iOS 7. The spinner doesn't spin

Here is the function that creates a layer with spinner

- (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;

}

有帮助吗?

解决方案

Fixed it by adding the animation only in viewDidAppear of the viewcontroller that was displaying the Image view.

Helpful insight from here

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top