【发布时间】:2014-09-03 07:14:49
【问题描述】:
我一直试图在 iOS 8 上关闭模式表单视图,但没有成功, 我试过这段代码
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapBehind:)];
[recognizer setNumberOfTapsRequired:1];
recognizer.cancelsTouchesInView = NO; //So the user can still interact with controls in the modal view
[self.view.window addGestureRecognizer:recognizer];
- (void)handleTapBehind:(UITapGestureRecognizer *)sender
{
if (sender.state == UIGestureRecognizerStateEnded)
{
CGPoint location = [sender locationInView:nil]; //Passing nil gives us coordinates in the window
//Then we convert the tap's location into the local view's coordinate system, and test to see if it's in or outside. If outside, dismiss the view.
if (![self.view pointInside:[self.view convertPoint:location fromView:self.view.window] withEvent:nil])
{
// Remove the recognizer first so it's view.window is valid.
[self.view.window removeGestureRecognizer:sender];
[self dismissModalViewControllerAnimated:YES];
}
}
}
但它没有检测到外部视图点击,有什么建议吗?
【问题讨论】:
-
我已经发布了我尝试过的代码的链接。
-
贴出您的相关代码,而不是其他人的代码。此外,没有工作 不是有效的问题描述。
-
更新问题,请看。
-
我还没有找到任何解决方案,但我正在关注这个讨论:stackoverflow.com/questions/9102497/…
标签: ios objective-c ipad