Get a vector from a UIPanGestureRecognizer
我正在尝试从
这可能吗?它没有Direction属性,并且文档中的翻译说明有些混乱。我是否需要手动创建一个中心点(关于视图的中心),并比较
谢谢! ^ _ ^
如果可以使用:
来获取速度
1 | CGPoint velocity = [recognizer velocityInView:self.view] |
然后您可以使用以下方法计算相对于x轴的angular:
1 2 3 4 5 | float x = velocity.x; float y = velocity.y; double angle = atan2(y, x) * 180.0f / 3.14159f; if (angle < 0) angle += 360.0f; |
1 2 3 4 5 6 7 8 9 10 11 12 13 | CGPoint startLocation = [sender locationInView:self.view]; if (sender.state == UIGestureRecognizerStateBegan) { startLocation = [sender locationInView:self.view]; } else if (sender.state == UIGestureRecognizerStateEnded) { CGPoint stopLocation = [sender locationInView:self.view]; CGFloat dx = stopLocation.x - startLocation.x; CGFloat dy = stopLocation.y - startLocation.y; double angle = atan2(dy, dx) * 180.0f / M_PI; if (angle < 0) angle += 360.0f; NSLog(@"angle: %f",angle); } |