[英]Presenting view controller response touch events when modal view controller is presented
Here is the code: 这是代码:
UIStoryboard *myStoryboard = [UIStoryboard storyboardWithName:@"StoryboardName" bundle:nil];
UIViewController *presentedViewController = [myStoryboard instantiateViewControllerWithIdentifier:@"IdentifierName"];
presentedViewController.modalPresentationStyle = UIModalPresentationFormSheet;
presentingViewController presentViewController:presentedViewController animated:NO completion:nil];
the view of presentingViewController would not response any touch event, but I want it to take touch events,what should I do? presentingViewController的视图不会响应任何触摸事件,但是我希望它接受触摸事件,我该怎么办? Appreciate for any suggestion! 感谢任何建议!
This is the expected behavior and should be what you see in most apps. 这是预期的行为,应该是您在大多数应用中看到的。 Apple's App Store app does allow you to tap outside the modal form sheet to dismiss it, however, so there's some precedent for it being acceptable, in a limited way. Apple的App Store应用程序确实允许您在模式表单之外点击以将其关闭,因此,在有限的范围内,有一些先例可以接受。 If your design absolutely requires it, consider setting up and tearing down a window-based gesture recognizer in the presented view controller. 如果您的设计绝对需要,请考虑在提供的视图控制器中设置和拆除基于窗口的手势识别器。
For example, to implement the tap-outside-to-dismiss behavior, configure a tap gesture recognizer in viewDidAppear:
. 例如,要实现轻拍从外部到关闭的行为,请在viewDidAppear:
配置轻viewDidAppear:
手势识别器。 You can remove it on viewWillDisappear:
if it still exists at the time that is called. 您可以在viewWillDisappear:
上将其删除viewWillDisappear:
如果在调用时它仍然存在。
In the tap handler, you'd want to get the location of the tap in window coordinates, ie: 在轻敲处理程序中,您想获取轻敲在窗口坐标中的位置,即:
CGPoint tapPoint = [recognizer locationInView:nil];
You could then do some work with geometry to check and see if the tap occurred on the modally-presented view or outside (over the dimmed region that corresponds to your presenting view controller). 然后,您可以对几何图形进行一些检查,以查看是否在模态表示的视图上或外部(在与您的呈现视图控制器相对应的变暗区域上)发生了敲击。 UIView has a pointInside:withEvent:
method that might help with that. UIView有一个pointInside:withEvent:
方法可能对此有所帮助。
Here is the simple way to present viewcontroller... 这是呈现ViewController的简单方法...
ViewController *view = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewController"];
[self presentViewController:view animated:YES completion:nil];
Enjoy code 享受代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.