【问题标题】:Cancel UITouch Events When View Covered By Modal UIViewController模态UIViewController覆盖View时取消UITouch事件
【发布时间】:2010-03-27 23:35:09
【问题描述】:

我正在编写一个应用程序,用户必须用手指在屏幕上移动一些东西并放下它们。为此,我使用了必须移动的每个视图的 touchesBegan,touchesEnded... 函数。

问题是有时视图被使用 [UIViewController presentModalViewController] 函数显示的视图覆盖。一旦发生这种情况,我移动的 UIView 就会停止接收触摸事件,因为它被掩盖了。但是没有事件告诉我它停止接收事件,所以我可以重置移动视图的状态。

下面是一个例子来说明这一点。这些函数是主窗口中显示的 UIView 的一部分。它监听触摸事件,当我将手指拖动一段距离时,它会呈现一个覆盖所有内容的模态视图。在运行日志中,它会打印接收到的触摸事件。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
  NSLog(@"touchesBegan");

  touchStart=[[touches anyObject] locationInView:self];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
  CGPoint touchAt=[[touches anyObject] locationInView:self];
  float xx=(touchAt.x-touchStart.x)*(touchAt.x-touchStart.x);
  float yy=(touchAt.y-touchStart.y)*(touchAt.y-touchStart.y);
  float rr=xx+yy;

  NSLog(@"touchesMoved %f",rr);
  if(rr > 100) {
    NSLog(@"Show modal");
    [viewController presentModalViewController:[UIViewController new] animated:NO];
  }
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
  NSLog(@"touchesEnded");
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
  NSLog(@"touchesCancelled");
}

但是当我测试应用程序并触发要显示的模态对话框时,运行日志中的输出如下。

[会议于 2010-03-27 开始 16:17:14 -0700.] 2010-03-27 16:17:18.831 模型触摸取消[2594:207] 接触开始于 2010-03-27 16:17:19.485 模型触摸取消[2594:207] touchesMoved 2.000000 2010-03-27 16:17:19.504 模型触摸取消[2594:207] touchesMoved 4.000000 2010-03-27 16:17:19.523 模型触摸取消[2594:207] touchesMoved 16.000000 2010-03-27 16:17:19.538 模型触摸取消[2594:207] touchesMoved 26.000000 2010-03-27 16:17:19.596 模型触摸取消[2594:207] touchesMoved 68.000000 2010-03-27 16:17:19.624 模型触摸取消[2594:207] touchesMoved 85.000000 2010-03-27 16:17:19.640 模型触摸取消[2594:207] touchesMoved 125.000000 2010-03-27 16:17:19.641 modelTouchCancel[2594:207] 显示模态

关于如何在 UIView 的触摸事件被模态视图中断时重置其状态的任何建议?

【问题讨论】:

    标签: iphone modal-dialog uitouch touch-event


    【解决方案1】:

    如果您正在控制何时显示模态视图,您是否还可以同时发送通知来告诉应用程序的其余部分他们应该重置移动的视图?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-14
      • 2010-10-06
      • 1970-01-01
      • 1970-01-01
      • 2015-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多