8
我们目前使用的解决方案类似于here(参见Ares的回答)。这似乎不适用于iOS8。iOS8:关闭外接水龙头的表单
我有一个表单,我想在用户点击表单背后的暗视图时立即关闭它。 以前,通过在窗口中添加手势识别器并检查分支位置以查看它是否位于当前表单之外,这似乎是可能的;
我也注意到该设备的点需要转换(开关x和y)在横向模式下使用。除此之外,现在它只接收表单内部发生的手势,在屏幕上的任何点击手势之前触发事件。
- (void)viewDidLoad
{
[super viewDidLoad];
self.recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapBehind:)];
self.recognizer.numberOfTapsRequired = 1;
self.recognizer.cancelsTouchesInView = NO;
[self.view.window addGestureRecognizer:self.recognizer];
}
- (void)handleTapBehind:(UITapGestureRecognizer *)sender
{
if (sender.state == UIGestureRecognizerStateEnded)
{
CGPoint location = [sender locationInView:nil];
if (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) && IOS8)
{
location = CGPointMake(location.y, location.x);
}
// if tap outside pincode inputscreen
BOOL inView = [self.view pointInside:[self.view convertPoint:location fromView:self.view.window] withEvent:nil];
if (!inView)
{
[self.view.window removeGestureRecognizer:sender];
[self dismissViewControllerAnimated:YES completion:nil];
}
}
}
我不知道你是什么意思?这是如何反映ios8中的API更改?提到的代码在ios7中工作正常。或者这是一种规避ios8错误的方法? – 2014-09-15 19:00:42
为了让你发布的代码能够在iOS8中工作,在你的'self.recognizer'中添加一个'UIGestureRecognizerDelegate'并添加这些代理方法 – Erich 2014-09-15 19:03:33
是的,解决了它!谢谢:) – 2014-09-16 08:20:38