我在使用 Core Animation 旋转 UIView 子类对象以响应 UISwipeGesture 时遇到问题。
描述上下文:我有一个圆形表盘,我在 CG 中绘制并作为 subview 添加到主视图。 作为对滑动手势的响应,我指示它根据它是向左还是向右滑动向任一方向旋转 15 度。
它只会旋转一次的问题。随后的手势被识别(从触发的其他 Action 中可以看出)但动画不会重复。我可以向左走一次然后向右走一次。但是多次尝试朝任一方向前进是行不通的。这是相关代码,让我知道您的想法...
- (IBAction)handleLeftSwipe:(UISwipeGestureRecognizer *)sender
{
if ([control1 pointInside:[sender locationInView:control1] withEvent:nil])
{
//updates the display value
testDisplay.displayValue = testDisplay.displayValue + 0.1;
[testDisplay setNeedsDisplay];
//rotates the dial
[UIView animateWithDuration:0.25 animations:^{
CGAffineTransform xform = CGAffineTransformMakeRotation(radians(+15));
control1.transform = xform;
[control1 setNeedsDisplay];
}];
}
最佳答案
CGAffineTransform xform = CGAffineTransformMakeRotation(弧度(+15));
您是否总计旋转了多远。 CGAffineTransformMakeRotation 不是相加的。仅使用最新的。所以你每次都将它设置为 15,而不是每次都多 15。
关于ios - 使用 Core Animation 和 block 发出旋转 UIView 对象的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7249403/