【问题标题】:How to tell the difference between touchesBegan and touchesMoved如何区分 touchesBegan 和 touchesMoved
【发布时间】:2011-02-14 19:06:26
【问题描述】:

如何在用户捏住对象时忽略 touchesBegan 方法,而在用户点击屏幕时忽略 touchesMoved 方法?我创建了图片放大/缩小效果,我希望能够在用户点击屏幕一次时隐藏导航栏。现在,当用户开始捏合时,导航栏会在用户触摸一次后显示。

最好的方法是什么?

【问题讨论】:

    标签: ios4 multi-touch touchesbegan touchesmoved


    【解决方案1】:

    似乎对显示/隐藏导航栏最简单的方法是添加 UITapGestureRecognizer 并将 numberOfTouchesRequired 和 numberOfTapsRequired 设置为 1。

    或者,您可以使用 touchesEnded 而不是 touchesBegan。然后在您的 touchesEnded 中,您可以检查触摸次数,并且仅在为 1 时显示/隐藏:

    -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 
        UITouch *theTouch = [touches anyObject]; 
        if (theTouch.tapCount == 1) {
            // show/hide navigation here ...
        } else {
            // finish your zoom here ...
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2012-12-22
      • 2011-03-21
      • 1970-01-01
      • 2016-01-28
      • 1970-01-01
      • 1970-01-01
      • 2013-01-29
      • 2010-11-10
      • 1970-01-01
      相关资源
      最近更新 更多