我想使用touchesMoved
方法在屏幕上旋转图像。
因此,如果我将手指从右侧移动到左侧,我想要我的手指
图像从左向右旋转。
这有可能吗?
答案 0 :(得分:0)
找到解决方案!
- (void)handleDragFrom:(CGPoint)start to:(CGPoint)end
{
[super handleDragFrom:start to:end];
float rotationCenterX = self.player.position.x - (self.player.contentSize.width / 2);
float rotationCenterY = self.player.position.y - (self.player.contentSize.height / 2);
float dXStart = start.x - rotationCenterX;
float dYStart = start.y - rotationCenterY;
float radianStart = atan2(dYStart, dXStart);
float dXEnd = end.x - rotationCenterX;
float dYEnd = end.y - rotationCenterY;
float radianEnd = atan2(dYEnd, dXEnd);
float radian = GLKMathRadiansToDegrees(radianEnd - radianStart);
self.player.rotation -= radian;
}
“开始”和“结束”是移动触摸给出的两点:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
CGPoint end = [touch locationInView:self.view];
CGPoint start = [touch previousLocationInView:self.view];
[self.scene handleDragFrom:start to:end];
}