@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. [C++程序设计]指针总结

  2. [C++程序设计]用数组名作函数参数

    1. 用数组元素作函数实参 #include <iostream> using namespace std; int max_value(int x, int max) { return ...

  3. [转]如何正确设置nginx中remote_addr和x_forwarded_for参数

    做网站时经常会用到remote_addr和x_forwarded_for这两个头信息来获取客户端的IP,然而当有反向代理或者CDN的情况下,这两个值就不够准确了,需要调整一些配置. 什么是remote ...

  4. LFS,编译自己的Linux系统 - 包和补丁

    建立工作目录 我们先建立一个工作目录,用于存放下载的源代码和对源代码进行编译. sudo mkdir –v /mnt/lfs/sources sudo chmod –v a+wt /mnt/lfs/s ...

  5. dataGridView行高自适应

    今天从网上查询相关datagridview行高自适应的信息时,好多都是告诉你直接用下面三行代码: dataGridView1.AutoSizeRowsMode = DataGridViewAutoSi ...

  6. mysql null值转换

    1.如果为空返回0 select ifnull(null,0) 2.如果为空返回0,否则返回1 select if(isnull(col),0,1) as col.

  7. 【Xamarin挖墙脚系列:IOS现有的设备SDK /OS/硬件一览】

    附件下载: http://pan.baidu.com/s/1o7rsrUE

  8. iOS开发之property属性介绍

    大家都知道@property和@synthesize可以自动生成某个类成员变量的存取方法,但可能对property中的一些属性不是很了解,网上的一些介绍有的不是很正确,感觉会误导新手,于是准备详细介绍 ...

  9. 在非MFC的win 32程序里面能够使用CString类

    论坛有会员用到了.,今天给大家说说CSring如何在非mfc下的调用第一:先要包含 #include "afx.h" 包含之后会报windows.h重复定义我们需要把这个头文件包含 ...

  10. Kth Smallest Element in Unsorted Array

    (referrence: GeeksforGeeks, Kth Largest Element in Array) This is a common algorithm problem appeari ...