【问题标题】:How to cancel uitouches?如何取消uitouches?
【发布时间】:2011-07-01 21:20:54
【问题描述】:

在我的应用程序中,我想让用户点击屏幕左侧以提高他们的速度并在右侧滑动以使用操纵杆。但是,如果用户一直按住左侧,则操纵杆将无法正常工作。

我正在使用 touchesBegan、touchesMoved 等。有没有办法可以取消第一次触摸时的信息并单独操作操纵杆?

我已经试过[self touchesCancelled: touches withEvent: event];有没有其他办法?

【问题讨论】:

    标签: iphone uitouch touchesbegan touchesmoved


    【解决方案1】:

    Cocoa Touch 框架支持多点触控。因此,您不必取消第一次触摸即可使用第二次触摸。只需枚举触摸并仅使用您想要的触摸代理中的操纵杆即可。

    NSArray  *allTouches = [ touches allObjects ];
    int      numTouches  = [ allTouches count ];
    for (int i=0; i<numTouches; i++) {
        UITouch *theTouch = [ allTouches objectAtIndex:i ];
        if (theTouch != leftSideHoldTouch) {
            // maybe it's a joystick touch, so handle it here
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-08
      • 1970-01-01
      • 1970-01-01
      • 2012-08-11
      • 1970-01-01
      • 2017-09-02
      • 2023-03-24
      相关资源
      最近更新 更多