我正在编写一个应用程序,用户必须使用他的手指在屏幕上移动一些内容并将其丢弃。为此,我使用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 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状态的任何建议吗?
答案 0 :(得分:0)
如果您正在控制何时显示模态视图,您是否还可以同时发送通知以告知应用的其余部分他们应该重置移动的视图?