我在这里有点难过。如果用户选择表单之外的任何位置,我有一个UIModalPresentationFormSheet
并且我添加了一个手势识别器来处理关闭表单。我在表单顶部的导航栏中也有一个取消按钮。当用户选择表单外的任何位置以使用手势识别器关闭表单时,一切正常。但是当他们使用取消按钮时,忽略手势识别器,一旦表单关闭,我就会收到以下错误。我相信它从识别器被发送到 handleTapBehind 方法。我不明白为什么,因为当视图被关闭时,viewWillAppear
不应该调用将识别器分配给已释放方法(handleTapBehind
)的方法。
错误:
[CallWebViewViewController handleTapBehind:]:消息发送到释放的实例 0x21ee5db0
代码:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
if(UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM())
{
if(![self.view.window.gestureRecognizers containsObject:recognizer])
{
recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapBehind:)];
[recognizer setNumberOfTapsRequired:1];
recognizer.cancelsTouchesInView = NO;
[self.view.window addGestureRecognizer:recognizer];
}
}
}
- (void)handleTapBehind:(UITapGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateEnded)
{
CGPoint location = [sender locationInView:nil];
if (![self.view pointInside:[self.view convertPoint:location fromView:self.view.window] withEvent:nil])
{
[self dismissViewControllerAnimated:YES completion:nil];
[self.view.window removeGestureRecognizer:recognizer];
}
}
}