请告诉我如何旋转UIView(打开饼图),就好像它在枢轴上一样。只有在用户轻弹视图后,它才会旋转。
答案 0 :(得分:4)
你会使用这样的东西:
- (void)spin
{
CABasicAnimation *fullRotation;
fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotation.fromValue = [NSNumber numberWithFloat:0];
fullRotation.toValue = [NSNumber numberWithFloat:M_PI * 360 / 180.0];
fullRotation.duration = 0.25;
fullRotation.repeatCount = 1;
[self.view.layer addAnimation:fullRotation forKey:@"360"];
}
当你想旋转360º时,只需调用旋转方法。根据需要调整以旋转更多,更少,更快,更慢等等。
编辑:请注意,在上面的代码中,view
属性是我们正在旋转的属性,以防它不明显。因此,将self.view
更改为您要旋转的任何视图。