我有一个UIView-subclass对象的问题,我正在使用Core Animation旋转以响应UISwipeGesture。
描述上下文:我有一个圆形表盘,我在CG中绘制并作为子视图添加到主视图中。 为了响应滑动手势,我指示它在任一方向上旋转15度,具体取决于是否向左或向右滑动。
它只会单向旋转一次的问题。识别后续手势(从触发的其他动作中可以看出),但动画不会重复。我可以一次离开一次。但是尝试多次向两个方向前进都不起作用。这是相关的代码,让我知道你的想法......
- (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];
}];
}
答案 0 :(得分:3)
CGAffineTransform xform = CGAffineTransformMakeRotation(弧度(+15));
你总是保持旋转的距离。 CGAffineTransformMakeRotation不是附加的。仅使用最新的。所以你每次都要设置为15,而不是每次15次。
答案 1 :(得分:1)
这是一个累积旋转视图的超级简单示例。每按一次按钮,视图旋转180度。
- (IBAction) onRotateMyView: (id) sender
{
[UIView animateWithDuration:0.3 animations:^{
myView.transform = CGAffineTransformMakeRotation(M_PI/2*rotationCounter);
} completion:^(BOOL finished){
//No nothing
}];
++rotationCounter;
}