【问题标题】:iOS Recognize that a touch was made but don't intercept itiOS 识别触摸但不拦截
【发布时间】:2012-04-05 12:28:21
【问题描述】:

我有一个我正在展示的视图。该视图与 UITableView 出现在同一屏幕上。当触摸屏幕上的任何位置时,我想关闭视图,但我不想阻止该触摸到达其目标。例如,如果用户去滚动表格视图或选择一个单元格或任何东西 - 我想知道这样我可以关闭视图,但我希望用户触摸的任何东西都能像往常一样做出反应。任何帮助都会很棒。

【问题讨论】:

    标签: iphone ios uikit uigesturerecognizer uiresponder


    【解决方案1】:

    在该 UIView 的类上实现 hitTest:withEvent: 方法。检查触摸的位置。如果您的视图框架不包含它 - 关闭视图。

    【讨论】:

      【解决方案2】:

      希望对你有帮助:

      - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
      {
        UITouch *touch = [[event allTouches] anyObject];
      
       CGPoint location = [touch locationInView: touch.view];
        if(CGRectContainsPoint(tableView.frame, location) || CGRectContainsPoint(anyOtherObject.frame, location))
       {
          [self performAction];
       }
      [self.view removeFromSuperView];
      }
      

      【讨论】:

        【解决方案3】:

        如果您使用 UIPopover 或 UIActionSheet,它将几乎完全显示此行为。我在 UITableView 和嵌入在 UIView 中的 UITableView 上完成了此操作。

        【讨论】:

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