【问题标题】:iPhone - Detecting touches and canceling them?iPhone - 检测触摸并取消它们?
【发布时间】:2011-08-01 02:51:49
【问题描述】:

我正在检测我的 UIView 上的触摸。 在某些情况下,我想取消触摸,这样 touchesEnded 就不会被调用。但是无论 touchesEnded 总是会被调用吗?

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
   if (SOMETHING_SPECIAL)
   {
      [super touchesCancelled:touches withEvent:event];
   }
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
   //I don't want it to get here if touches were canceled how can i do this?
}

- 在我的 touchesEnded 中,我如何确定触摸是否被取消?

【问题讨论】:

    标签: ios objective-c iphone uitouch touchescancelled


    【解决方案1】:

    TouchesEnded总是在您的触摸被取消与否的任何地方被调用,所以我建议改为使用那个确切的:

       if (SOMETHING_SPECIAL)
       {
    
       }
    

    在你的:

    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
    

    【讨论】:

    • 但是当触摸超出我的 UIView 框架时,我想取消触摸事件,但它没有这样做。这就是大多数 UI 元素的工作方式,我正在尝试遵循相同的模式
    • @Aryaxt 我明白你的意思,我不知道这是否可能。
    • 我最终使用了一个 BOOL 标志,当触摸开始时我设置为 NO,当触摸移出视图边界时我设置为 YES。
    【解决方案2】:

    要获取 touchesCancelled 事件,请从 UIResponder 实现此方法。

    touchesCancelled:withEvent:.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多