1
何我可以添加一個旋轉的對象除了拖動?iPhone編碼 - 如何添加旋轉到觸摸事件?
我不需要多點觸摸。
code:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
currentTouch = [touch locationInView:self.view];
CGFloat dx = currentTouch.x - carMove.position.x;
CGFloat dy = currentTouch.y - carMove.position.y;
CGFloat dist = sqrt(dx * dx + dy * dy);
if(dist <carMove.radius) {
carMove.velocity = CGPointMake(0.0, 0.0);
carMove.dragging = YES;
}
lastTouch = currentTouch;
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
currentTouch = [touch locationInView:self.view];
if(carmove.dragging){
carMove.position = currentTouch;
carMove.velocity = CGPointMake(currentTouch.x - lastTouch.x, currentTouch.y - lastTouch.y);
}
lastTouch = currentTouch;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
carMove.dragging = NO;
}
這將完整輪換,不是?我需要用戶根據需要旋轉圖像對象(而不必完全旋轉)。 – omri 2009-12-18 16:02:59
旋轉將是用戶旋轉到電話,是的。如果您希望手機旋轉控制更改爲用戶開始旋轉對象時相對於旋轉的旋轉,請將圖像和手機的原始旋轉存儲在圖像對象中,並且僅修改圖像旋轉,並且從初始位置狀態。 – martinr 2009-12-18 16:10:41
噢,如果你覺得這個有用,請將我和/或標記爲最佳答案。 Thx – martinr 2009-12-18 16:18:21