【问题标题】:uipangesturerecognizer with uiswipegesturerecognizeruipangesturerecognizer with uiswipegesturerecognizer
【发布时间】:2015-06-11 15:59:49
【问题描述】:

目前使用 panGesture 的滑动并不完美。如果用户想要向上滑动,但他向右移动了一个像素,但其余像素向上(用户向上滑动,但在开始时略微向右滑动),但右侧将被激活而向上不会。我认为集成 swipeGesture 可以最大限度地减少这种错误,但它似乎不起作用。我想要它,所以当用户在开始时没有完美地向上滑动时,仍然会激活向上而不是向左或向右。它确实可以向上、向左或向右移动,但并不是 100% 完美,因为用户只需更改 y 或 x 轴,这几乎是不可能的。

-(void)pan:(UIPanGestureRecognizer *)sender
{
CGPoint distance = [sender translationInView:self.view];
UISwipeGestureRecognizer *swiping;
[myImage addGestureRecognizer: swiping];

//Not Working
if(swiping.direction == UISwipeGestureRecognizerLeft || swiping.direction == UISwipeGestureRecognizerRight) {
NSLog(@"Verticle")
} else if(swiping.direction == UISwipeGestureRecognizerUp || swiping.direction == UISwipeGestureRecognizerDown) {
NSLog(@"Horizontal");
} else if(distance.x > 0 || distance.x < 0) { // From here down working but not perfect
NSLog(@"Verticle")
} else if (distance.y < 0 || distance.y > 0) {
NSLog(@"Horizontal")
}
[sender setTranslation:CGPointZero inView:self.view];
}

【问题讨论】:

    标签: ios objective-c uipangesturerecognizer uiswipegesturerecognizer


    【解决方案1】:

    您可以简单地使用 if 语句,而不是添加 UISwipeGestureRecognizer。如果它们首先“意外”按 x 坐标移动,您可以在说它是垂直的之前运行 if 语句。将 10 更改为您喜欢的 x 坐标变化。

    -(void)Pan: (UIPanGestureRecognizer *)sender
    {
        distance = [sender translationInView:self.view];
    
        if (distance.x > 0 || distance.x < 0) {
            if ((distance.y > 0 || distance.y < 0) && ((distance.x > 0 && distance.x < 10) || (distance.x < 0 && distance.x > -10))) {
                NSLog(@"Horizontal");
            } else {
                NSLog(@"Verticle");
            }
        } else if (distance.y > 0 || distance.y < 0) {
            NSLog(@"Starting Up Horizontal");
        }
        [sender setTranslation:CGPointZero inView:self.view];
    
        if (sender.state == UIGestureRecognizerStateEnded) {
            NSLog(@"Ended");
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-10
      相关资源
      最近更新 更多