我写在用户使用他的手指在屏幕上移动的一些东西,并把它们的应用程序。要做到这一点,我使用具有要移动的每个视图的的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分十四秒-0700] 2010-03-27   16:17:18.831   modelTouchCancel [2594:207]   的touchesBegan 2010-03-27 16:17:19.485   modelTouchCancel [2594:207]   touchesMoved 2.000000 2010-03-27   16:17:19.504   modelTouchCancel [2594:207]   touchesMoved 4.000000 2010-03-27   16:17:19.523   modelTouchCancel [2594:207]   touchesMoved 16.000000 2010-03-27   16:17:19.538   modelTouchCancel [2594:207]   touchesMoved 26.000000 2010-03-27   16:17:19.596   modelTouchCancel [2594:207]   touchesMoved 68.000000 2010-03-27   16:17:19.624   modelTouchCancel [2594:207]   touchesMoved 85.000000 2010-03-27   16:17:19.640   modelTouchCancel [2594:207]   touchesMoved 125.000000 2010-03-27   16:17:19.641   modelTouchCancel [2594:207]显示模式

上时其触摸事件由模态的视图中断如何重置一个UIView的状态的任何建议?

有帮助吗?

解决方案

如果你当显示模式视图控制,可你也同时发送通知,告诉您的应用程序的其他部分,他们应重置移动的看法?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top