我正在制作一个拼图游戏,需要在每个双击时将拼图块旋转90
度。
我尝试了两种不同的方法,第一种方法是这样的:
[UIView beginAnimations:@"rotate" context:nil];
[UIView setAnimationDuration:0.5];
self.transform = CGAffineTransformMakeRotation(90);
[UIView commitAnimations];
唯一的问题是这个部分没有旋转 90
度; 而是旋转了约 100
度,并且此动画正在修改拼图块的帧 UIView
。
这是我的控制台输出:
frame BEFORE ROTATION: {{35, 178}, {80, 80}}
frame AFTER ROTATION: {{21.3172, 164.317}, {107.366, 107.366}}
我尝试的第二种方法是这样的:CABasicAnimation* spinAnimation = [CABasicAnimation
animationWithKeyPath:@"transform.rotation"];
spinAnimation.toValue = [NSNumber numberWithFloat:1];
[self.layer addAnimation:spinAnimation forKey:@"spinAnimation"];
问题在于使用这种方法后,旋转结束后将会翻转我的 UIView
到先前的状态。如何在进行动画旋转时避免这些问题呢?