我有一个 UIImage,我希望用户能够旋转它,就像它是保险箱的转动按钮一样。我不希望图像在 0 < x < 360 范围内以任何角度转动,但我希望轮子(UIImage)停在不同的固定点之一(通常从 0 到 20)。例如,如果我有 3 个选项,用户将能够转动滚轮并将指针放在三个点上(在这种情况下,角度为:60、120、180)。我使用此代码来旋转图像:
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
}
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
NSSet *allTouches = [event allTouches];
int len = [allTouches count]-1;
UITouch *touch =[[allTouches allObjects] objectAtIndex:len];
CGPoint location = [touch locationInView:[self.SplashItGroupPicker superview]];
float theAngle = atan2( location.y-self.SplashItGroupPicker.center.y, location.x-self.SplashItGroupPicker.center.x );
int totalRadians = -3.14;
totalRadians += fabs(theAngle - totalRadians);
totalRadians = fmod(totalRadians, 2*M_PI);
[self rotateImage:totalRadians];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
}
-(void) rotateImage:(float)angleRadians{
self.SplashItGroupPicker.transform = CGAffineTransformMakeRotation(angleRadians);
CATransform3D rotatedTransform = self.SplashItGroupPicker.layer.transform;
self.SplashItGroupPicker.layer.transform = rotatedTransform;
}
我怎样才能得到那个结果?