UIImage があり、金庫の回転ボタンのようにユーザーが回転できるようにしたいと考えています。画像を 0 < x < 360 の範囲で任意の角度に回転させたくありませんが、ホイール (UIImage) を固定ポイントの 1 つで停止させたいと考えています。たとえば、3 つのオプションがある場合、ユーザーはホイールを回してポインターを 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;
}
どうすればその結果を得ることができますか?