FormSheet式模态视图,点击模态视图外隐藏模态视图的方法
2015-07-16 12:44
387 查看
- (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; _tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:selfaction:@selector(handleTapBehind:)]; [_tapRecognizer setNumberOfTapsRequired:1]; _tapRecognizer.cancelsTouchesInView = NO; [self.view.window addGestureRecognizer:_tapRecognizer]; [_tapRecognizer setDelegate:(id<UIGestureRecognizerDelegate>)self]; } - (void)handleTapBehind:(UITapGestureRecognizer *)sender { if (sender.state == UIGestureRecognizerStateEnded) { CGPoint location = [sender locationInView:nil]; if (UIDevice currentDevice]systemVersion] floatValue] < 8.0) { if (UIInterfaceOrientationIsLandscape([UIApplicationsharedApplication].statusBarOrientation)) { location = CGPointMake(location.y, location.x); } } if (![self.view pointInside:[self.view convertPoint:location fromView:self.view.window] withEvent:nil]) { [self.view.window removeGestureRecognizer:sender]; [self dismissViewControllerAnimated:YES completion:nil]; } } } #pragma mark - UIGestureRecognizer Delegate - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer { return YES; } - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer*)otherGestureRecognizer { return YES; } - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { return YES; }
相关文章推荐
- 关于递归调用,函数指针,数组,字符串的一些理解
- 类对象的复制
- hibernate中的个get()和load()的区别
- Linux下JavaEE环境的搭建(jdk,Tomcat,eclipse)
- 关于接口概念和网站访问并发性问题记录
- Mac下的UI自动化测试 (四)
- 不同分辨率的LCM进行兼容
- Keil、uVision、MDK、Keil C51之间的区别比较
- Java学习----继承和接口的区别是什么???
- 不同分辨率的LCM进行兼容
- Tomcat7.0更改默认的路径来访问自己的项目
- 在反思性学习
- .Net学习笔记----2015-07-16(C#基础复习02)
- 053第449题
- ANSI,UTF-8,Unicode,ASCII编码的区别
- Android HandlerThread 源码分析
- Divide Two Integers
- 一个类似backbone路由的纯净route ( 前端路由 客户端路由 backbone路由 )
- 黎万强的《参与感》到底写了什么?
- 给float元素居中