我有一个UIPanGestureRecognizer按钮。我想确定这样的手指方向:
if (sqrt(translation.x * translation.x) / sqrt(translation.y * translation.y) < 1)
{
isHorizontalScroll = YES;
}
else
{
isHorizontalScroll = NO;
}
在调用识别器的方法之前。
有人知道解决方案吗?
答案 0 :(得分:1)
使用touchesbegan,touchesmoved,touchesEnd
答案 1 :(得分:1)
嗯,当手势处于UIGestureRecognizerStateBegan状态时,听起来你应该在手势识别器中进行检查。例如:
- (void)handlePan:(UIGestureRecognizer *)sender {
CGPoint translation = [(UIPanGestureRecognizer*)sender translationInView:self.view];
switch (sender.state) {
case UIGestureRecognizerStateBegan:
if (sqrt(translation.x * translation.x) / sqrt(translation.y * translation.y) < 1)
isHorizontalScroll = YES;
else
isHorizontalScroll = NO;
break;
case UIGestureRecognizerStateChanged:
...
答案 2 :(得分:1)
实际上具体的实施取决于你。要做到这一点,你至少有3个杠杆:
重新实现UIResponder的方法:
– touchesBegan:withEvent:
– touchesMoved:withEvent:
– touchesEnded:withEvent:
重新实现UIWindow的方法:
– (void)sendEvent:(UIEvent *)event