iPad模态推出sheet,点击外部消失
2015-04-12 15:06
134 查看
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 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]; } } }
iOS7.0 可行, iOS8.0 handleTap不走
加代理
UIGestureRecognizerDelegate
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer*)otherGestureRecognizer { return YES; }
recognizer.delegate = self;
if (sender.state == UIGestureRecognizerStateEnded) {
UIView *rootView = self.view.window.rootViewController.view; CGPoint location = [sender locationInView:rootView]; if (![self.view pointInside:[self.view convertPoint:location fromView:rootView] withEvent:nil]) { [self dismissViewControllerAnimated:YES completion:^{ [self.view.window removeGestureRecognizer:sender]; }]; } }
可运行
原网页http://stackoverflow.com/questions/25638409/dismiss-modal-form-sheet-view-on-outside-tap-ios-8
相关文章推荐
- ipad开发 控制器模态显示(UIModalPresentationFormSheet)实现点击UIDimmingView回收键盘
- bootstrap 模态框model点击模态框外部不消失模态框的效果
- ProgressDialog 点击外部 弹窗不消失,点击back键可以返回
- PopupWindow点击外部区域消失(三)
- 点击PopupWindow外部消失
- 非模态的titlewindow,点击外部时的事件
- Bootstrap model的使用及点击外部不消失
- Android popupWindow 点击外部消失,点击外部其他控件触发其他事件
- Activity对话框,点击外部不消失
- android PopupWindow点击外部和返回键消失的解决方法
- jQuery点击弹出层弹出模态框点击模态框消失代码分享
- Android 响应menu,back键,点击外部消失
- PopupWindow点击外部和返回键消失遇到的坑
- 解决android中点击对话框外部,对话框消失的问题
- 模态弹窗,点击黑色半透明区域消失
- android 5.0 popuwindow 点击外部不消失
- Android4.0中Alertdialog对话框点击边缘外部消失问题解决
- 带输入框的自定义dialog 点击外部消失 输入框可以弹出软键盘 去除外部黑框
- Android开发之关于使用PopWindow点击外部不消失的解决实例
- edittext点击文本外部使软键盘消失