Mor*_*ess 10 transform core-graphics objective-c cgaffinetransform ios
这应该很简单,但我无法旋转UIImageView360度,永远重复.
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveLinear | UIViewAnimationOptionBeginFromCurrentState animations:^{
self.reloadButton.imageView.transform = CGAffineTransformRotate(self.reloadButton.imageView.transform, -M_PI);
} completion:^(BOOL finished) {
}];
Run Code Online (Sandbox Code Playgroud)
根据文档,我传递的角度的符号CGAffineTransformRotate确定旋转方向,但上面的代码逆时针旋转.与...相同M_PI.
以弧度表示的角度,此矩阵旋转坐标系轴.在iOS中,正值指定逆时针旋转,负值指定顺时针旋转.在Mac OS X中,正值指定顺时针旋转,负值指定逆时针旋转.
yin*_*kou 14
Christoph已经采用了正确的方式,但是有一种更好的方法可以让它保持旋转状态,而不会在动画代表每次结束时重新调整它.这是完全错误的.
只需将动画的repeatCount属性设置为HUGE_VALF.
CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
animation.fromValue = @0.0f;
animation.toValue = @(2*M_PI);
animation.duration = 0.5f; // this might be too fast
animation.repeatCount = HUGE_VALF; // HUGE_VALF is defined in math.h so import it
[self.reloadButton.imageView.layer addAnimation:animation forKey:@"rotation"];
Run Code Online (Sandbox Code Playgroud)
如文档中所述,这将导致动画永远重复.
| 归档时间: |
|
| 查看次数: |
10510 次 |
| 最近记录: |