這是一個複雜的問題。簡單的答案是:使用一個平移手勢識別器,以:
- (void)panBegan:(UIPanGestureRecognizer *)pan {
CGRect frame = [self frame];
_central = CGPointMake(frame.origin.x+frame.size.width/2, frame.origin.y+frame.size.height/2);
CGPoint p = [pan locationInView:[self superview]];
p.x -= _central.x;
p.y -= _central.y;
_angle = atan2(p.x, p.y);
}
- (void)panMoved:(UIPanGestureRecognizer *)pan {
CGPoint p = [pan locationInView:[self superview]]];
p.x -= _central.x;
p.y -= _central.y;
CGFloat deltaAngle = _angle - atan2(p.x, p.y);
self.transform = CGAffineTransformMakeRotation(deltaAngle + _finalAngle);
}
其中_angle是盤的初始觸摸的角度,和_finalAngle在先前的盤的端保存的角度。
但是:UIPanGestureRecognizer具有velocity屬性,您應該在平底鍋上使用它來繼續旋轉,就好像錶盤具有慣性一樣。而且,如果撥號盤有一個固定的整數合法停止位置集合,那麼您必須調整減速曲線,使其停在合法的停止位置。而且,如果您製作減速動畫,並且用戶在前一個完成之前開始新的平移,則必須根據感知位置而不是存儲位置調整_finalAngle。
非常好。謝謝史蒂夫。有誰知道那裏是否有示例教程? – 2012-01-06 20:45:54