我已经实现了一个速度计。我有一个箭头图像。我想用手指轻轻地将它旋转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