我正在尝试向视图添加微调器并使用以下代码为其设置动画。它在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;
}