我已經實現了一個速度計。我有一個箭頭圖像。我想用手指輕輕地將它旋轉0°至180°,同時我也應該給出界限。這怎麼可能?速度計中的箭頭旋轉
這是我的代碼(在UIImageView
類別):
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
UITouch *touch = [touches anyObject];
CGPoint currentLocation = [touch locationInView:self.superview];
CGPoint pastLocation = [touch previousLocationInView:self.superview];
CGPoint d1 = CGPointMake(currentLocation.x-self.superview.center.x, currentLocation.y-self.superview.center.y);
CGPoint d2 = CGPointMake(pastLocation.x-self.superview.center.x, pastLocation.y-self.superview.center.y);
CGFloat angle1 = atan2(d1.y, d1.x);
CGFloat angle2 = atan2(d2.y, d2.x);
self.transform = CGAffineTransformRotate(self.transform, angle1-angle2);
}
它旋轉0到360度,我需要像20至160度的角度之間限制。
如果你提供了一些實際的代碼並獲得有關該代碼的反饋,而不是問這樣一個普通的問題,那麼你會從Stack Overflow中得到最好的結果。 – theTRON 2012-02-09 13:22:42
可能的重複[http://stackoverflow.com/questions/9210346/how-to-rotate-needle-just-like-car-speedo-meter-with-boundaries-in-ios](http://stackoverflow。問題/ 9210346 /如何旋轉針只是像汽車速度米與邊界在IOS) – Beuj 2012-02-09 13:23:15