具有关于stackoverflow的几个示例的代码。但是我的图像没有旋转..知道为什么吗?它显示在屏幕上,但是固定的。.
-(UIImageView *)movablePropeller
{
if(!_movablePropeller){
_movablePropeller = [[UIImageView alloc] initWithFrame:self.frame];
_movablePropeller.image = [UIImage imageNamed:@"MovablePropeller"];
[self addSubview:_movablePropeller];
}
return _movablePropeller;
}
- (void)startPropeller
{
CABasicAnimation *rotation;
rotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotation.fromValue = [NSNumber numberWithFloat:0.0f];
rotation.toValue = [NSNumber numberWithFloat:(2 * M_PI)];
rotation.cumulative = true;
rotation.duration = 0.7f; // Speed
rotation.repeatCount = INFINITY; // Repeat forever. Can be a finite number.
[self.movablePropeller.layer removeAllAnimations];
[self.movablePropeller.layer addAnimation:rotation forKey:@"Spin"];
}
(当然,我很乐意将其放在单独的线程中,而不是阻塞UI)