gpt4 book ai didi

Iphone SDK 通过单击 iPad 上的模态视图 Controller 外部来关闭它

转载 作者:行者123 更新时间:2023-12-03 18:10:44 26 4
gpt4 key购买 nike

当用户点击模态视图之外时,我想关闭 FormSheetPresentation 模态视图 Controller ...我见过很多应用程序这样做(例如 ipad 上的 eBay),但我不知道如何实现,因为下面的 View 是当模态视图像这样显示时禁用触摸(他们是否将其呈现为弹出窗口?)...有人有任何建议吗?

最佳答案

我晚了一年,但这很简单。

让模态视图 Controller 将手势识别器附加到 View 的窗口:

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];
[recognizer release];

处理代码:

- (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];
}
}
}

就是这样。天哪,这是一个有用且通常直观的行为。

关于Iphone SDK 通过单击 iPad 上的模态视图 Controller 外部来关闭它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2623417/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com