我可以连续旋转一定数量的图像,但我想将图像旋转一点,暂停,多一点,暂停等等。
以下代码不断执行此操作:
// rotate
CGFloat finalValue = 360 / 14.f;
CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
[rotationAnimation setFromValue:[self degreesToNumber:0]];
[rotationAnimation setToValue:[self degreesToNumber:finalValue]];
[rotationAnimation setDuration:5.0];
[rotationAnimation setRemovedOnCompletion:NO];
[rotationAnimation setFillMode:kCAFillModeForwards];
[self.secondHandImageView.layer addAnimation:rotationAnimation forKey:@"rotate"];
有没有办法将这个包装在一个for循环中,我需要的角度变化数量,并设置特定动画的持续时间和延迟?我没有尝试过任何工作。以下是我目前正在尝试的内容:
// rotate in ticks, so
NSTimeInterval delay = 0;
CGFloat currentAngle = 0;
CGFloat finalAngle = 360 / 14.f;
// angle difference
CGFloat numberOfTicks = 25.f;
CGFloat angleDelta = finalAngle / numberOfTicks;
for (NSUInteger tick = 0; tick < numberOfTicks; tick++) {
[UIView animateWithDuration:0.1 delay:delay options:UIViewAnimationOptionCurveLinear animations:^{
self.secondHandImageView.layer.transform = CATransform3DMakeRotation(0, 0, angleDelta, 1.0);
} completion:nil];
// update delay
delay += .2; // 200 milliseconds, 5 tickets every second
currentAngle += angleDelta;
}
答案 0 :(得分:0)
您的代码没问题 - 除了您无法为UIView动画块中的图层设置动画。相反,您可以为视图设置动画。用(2D)视图变换替换(3D)图层变换:
self.secondHandImageView.transform =
CGAffineTransformRotate(self.tickView.transform,angleDelta);