我想旋轉圖像。這我成功了。問題是,當我點擊並輕微拖動時,圖像完全旋轉到達點擊位置,然後順時針拖動圖像,然後緩慢旋轉。我擔心它爲什麼會完全旋轉到我拖着的地方。我想拖動從找到的位置開始,而不是旋轉到我的手指停下的位置,然後從那裏開始。使用目標旋轉圖像C
這是我的代碼:
-
(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 superview]];
float theAngle = atan2(location.y-self.center.y, location.x-self.center.x);
totalRadians = theAngle;
[self rotateImage:theAngle];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
}
-(void) rotateImage:(float)angleRadians{
self.transform = CGAffineTransformMakeRotation(angleRadians);
CATransform3D rotatedTransform = self.layer.transform;
self.layer.transform = rotatedTransform;
}
難道我做錯了什麼?
謝謝!
我懷疑問題出在你的rotateImage:方法你介意發佈代碼嗎? – Mattia 2010-11-01 00:38:23
它有 - 在代碼片段底部 – Lilz 2010-11-02 15:38:03