@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);

#pragma -mark 点击模态视图外的空白处隐藏模态视图

- (void)viewDidAppear:(BOOL)animated

{

[super viewDidAppear:animated];

_tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapBehind:)];

[_tapRecognizer setNumberOfTapsRequired:1];

_tapRecognizer.cancelsTouchesInView = NO; //So the user can still interact with controls in the modal view

[self.view.window addGestureRecognizer:_tapRecognizer];

[_tapRecognizer setDelegate:(id<UIGestureRecognizerDelegate>)self];

}

- (void)handleTapBehind:(UITapGestureRecognizer *)sender

{

if (sender.state == UIGestureRecognizerStateEnded) {

// passing nil gives us coordinates in the window

CGPoint location = [sender locationInView:nil];

// swap (x,y) on iOS 8 in landscape

if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0f) {

if (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {

location = CGPointMake(location.y, location.x);

}

}

// 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 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;

}

转载:http://my.oschina.net/CreeveLiu/blog/347913

@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);

FormSheet式模态视图,点击模态视图外隐藏模态视图的方法的更多相关文章

  1. 点击页面其它地方隐藏该div的方法

    思路一 第一种思路分两步 第一步:对document的click事件绑定事件处理程序,使其隐藏该div 第二步:对div的click事件绑定事件处理程序,阻止事件冒泡,防止其冒泡到document,而 ...

  2. jQuery实现鼠标点击Div区域外隐藏Div

    冒泡定义:当一个元素上的事件被触发的时候,比如说鼠标点击了一个按钮,同样的事件将会在那个元素的所有祖先元素中被触发.这一过程被称为事件冒泡:这个事件从原始元素开始一直冒泡到DOM树的最上层.(摘自网络 ...

  3. js实现的点击div区域外隐藏div区域

    首先看下JS的事件模型,JS事件模型为向上冒泡,如onclick事件在某一DOM元素被触发后,事件将跟随节点向上传播,直到有click事件绑定在某一父节点上,如果没有将直至文档的根. 阻止冒泡:1.对 ...

  4. js实现的点击div区域外隐藏div区域(转)

    首先看下JS的事件模型,JS事件模型为向上冒泡,如onclick事件在某一DOM元素被触发后,事件将跟随节点向上传播,直到有click事件绑定在某一父节点上,如果没有将直至文档的根. 阻止冒泡: 1. ...

  5. jquery实现点击展开列表同时隐藏其他列表 js 对象操作 对象原型操作 把一个对象A赋值给另一个对象B 并且对象B 修改 不会影响 A对象

    这篇文章主要介绍了jquery实现点击展开列表同时隐藏其他列表的方法,涉及jquery鼠标事件及节点的遍历与属性操作技巧,具有一定参考借鉴价值,需要的朋友可以参考下 本文实例讲述了jquery实现点击 ...

  6. iOS:视图切换的第一种方式:模态窗口

    一.UIModalController:模态窗口(一个控制器模态出另一个控制器的模态窗口) 当我们在view controller A中模态显示view controller B的时候,A就充当pre ...

  7. 从零开始实现ASP.NET Core MVC的插件式开发(一) - 使用ApplicationPart动态加载控制器和视图

    标题:从零开始实现ASP.NET Core MVC的插件式开发(一) - 使用Application Part动态加载控制器和视图 作者:Lamond Lu 地址:http://www.cnblogs ...

  8. el-dialog模态窗点击空白不消失

    通过查阅ElementUI的官方文档,可以发现Dialog对话框组件提供了一个close-on-click-modal属性来设置el-dialog模态窗点击空白不消失. <el-dialog : ...

  9. 阻止Bootstrap 模态框点击背景空白处自动关闭

    问题描述 模态框点击空白处,会自动关闭,怎么阻止关闭事件呢? 解决方法 在HTML页面中编写模态框时,在div初始化时添加属性 aria-hidden=”true” data-backdrop=”st ...

随机推荐

  1. Ubuntu安装字体的方法

    基本步骤如下: 1. 将要安装的字体放在一个文件夹下,以/home/UsrName/Download/Font为例 2.在终端中输入 sudo cp -r /home/UsrName/Download ...

  2. web.py安装

    web.py 是python的一个web插件,用于发布web服务安装下载web.py https://github.com/webpy/webpy 安装 解压下载的rar 打开控制台并定位到此文件夹输 ...

  3. Django学习(七) 创建第一个Django项目

    如果这是你第一次使用Django,你必须进行一些初始设置.即,您将需要自动生成一些代码,建立了Django项目. 从命令行.cd进入一个目录,你想要存储您的代码,然后运行以下命令: django-ad ...

  4. Java 正则提取数字串

    例如:有一个字符串:"数量最低2000份",将其中的2000数字提取出来. String arg0 = "数量最低2000份"; Pattern p = Pat ...

  5. cf479C Exams

    C. Exams time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...

  6. 【LeetCode练习题】Minimum Depth of Binary Tree

    Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the n ...

  7. Java连接各类数据库

    几种常用数据库的连接,以及Dao层的实现. 1.加载JDBC驱动: 1 加载JDBC驱动,并将其注册到DriverManager中: 2 //MySQL数据库 3 Class.forName(&quo ...

  8. [Android] 停止、恢复 背影音乐的播放

    在执行录音操作时,我们希望可以将酷狗等后台播放的音乐停掉,在录音完成后再恢复播放,可以使用以下代码: /**@param bMute 值为true时为关闭背景音乐.*/ @TargetApi(Buil ...

  9. Python 练习 —— 2048

    1. 引言 2048 这段时间火的不行啊,大家都纷纷仿造,"百家争鸣",于是出现了各种技术版本号:除了手机版本号,还有C语言版.Qt版.Web版.java版.C#版等,刚好我接触P ...

  10. java学习笔记day03

    1.二维数组,即一维护 int[][] arr1 = new int[3][2]; int[][] arr2 ={{2,4,3,6,22,7},{3,6,8,9},{10,13,24,5}}; pub ...