我想在用户点击模态视图时解雇FormSheetPresentation模式视图控制器...我已经看到一堆应用程序这样做(例如在ipad上的ebay)但我无法弄清楚如何从触摸中禁用底层视图当模态视图像这样显示时(他们是否可能将它呈现为一个弹出窗口?)......任何人都有任何建议吗?
我一直试图在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 …Run Code Online (Sandbox Code Playgroud) 我们目前正在使用类似于此处提到的解决方案(请参阅Ares的答案).这在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];
}
}
}
Run Code Online (Sandbox Code Playgroud) 我不知道如何在Swift中实现以下功能:
我在我的iPad应用程序中显示模态表单弹出窗口.为了驳回这个观点,我添加了一个解除它的按钮.但我真正想要的是当你点击视图外面时它会被忽略.与popover几乎相同的行为.我尝试通过添加点击手势来实现这一点,使其成为一个弹出窗口,任何演示样式,没有任何作用.
有人可能这样做,以便你可以指出我正确的方向?