【问题标题】:UISwipeGestureRecognizer swipe left and finger upUISwipeGestureRecognizer 向左滑动手指并向上滑动
【发布时间】:2015-04-16 06:29:02
【问题描述】:

我正在使用UISwipeGestureRecogizer 滑动leftright 使用UISwipeGestureRecognizerDirectionRightUISwipeGestureRecognizerDirectionLeft 并且它的工作完全正常,但默认滑动过于敏感,它只是比点击多一点.

有什么方法可以让它像scrollView 工作时一样工作,当它的paging enable 属性为真时,直到用户没有抬起手指,它才工作。
如果视图不随着手指的移动而移动,这很好,并且仅在执行leftright 手势并抬起手指时才起作用。谢谢。

【问题讨论】:

    标签: ios objective-c uiswipegesturerecognizer swipe-gesture


    【解决方案1】:

    UISwipeGestureRecognizer 不会给您任何选项来更改滑动的灵敏度或任何其他方面。要获得对滑动的更多控制,您可以使用以下方法之一:

    UIPanGestureRecognizer

    下面是 UIPanGestureRecognizer 的尝试:

    - (void)handleGesture:(UIPanGestureRecognizer *)gestureRecognizer{
        CGPoint velocity = [gestureRecognizer velocityInView:yourView];
        if(velocity.x > 0){
            //Right gesture
        }else{
            //Left gesture
        }
    }
    

    UIResponder

    所有UIViews都继承自UIResponder,因此您可以使用touchesBegantouchesMovedtouchesEnded方法来计算触摸。试试这样的:

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
        UITouch *touch = [touches anyObject];
        start = [touch locationInView:self.view];
    }
    
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
        UITouch *touch = [touches anyObject];
        CGPoint end = [touch locationInView:self.view];   
        //Compare start and end points here.
    }
    

    【讨论】:

    • 感谢您及时详细的回答,我会尝试并告诉您。
    • 正是我需要的,但使用后我知道这不符合我的要求,但答案是正确的,接受的答案和竖起大拇指。谢谢:)
    • 没问题。很高兴我能帮忙:)
    猜你喜欢
    • 2015-07-10
    • 2011-07-23
    • 1970-01-01
    • 2013-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多