@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. Joomla 二次开发 学习笔记

    Joomla目录结构 /administrator 管理后台的路径 /cache 是缓存目录 /components 是组件(component)目录 /includes 是一个重要的目录,里面都是J ...

  2. Python之路第十二天,高级(6)-paramiko

    paramiko 一.安装 pip3 install paramiko 二.使用 SSHClient 用于连接远程服务器并执行基本命令 1. 基于用户和密码链接 import paramiko # 创 ...

  3. php 实现同一个账号同时只能一个人登录

    php 实现同一个账号同时只能一个人登录 张映 发表于 2015-01-22 分类目录: php 标签:mysql, nginx, openfire, php, redis 以前考虑过这个问题,今天实 ...

  4. 火星A+B

    火星A+B Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  5. ubuntu安装配置gradle

    在Ubuntu安装Gradle也是很简单.切记请勿使用apt-get安装Gradle.因为Ubuntu源的Gradle实在太旧.安装好基本不能用. 下面是安装步骤: 1.在官网下载最新的Gradle版 ...

  6. STM32工程中出现 error: A1163E: Unknown opcode R0, , expecting opcode or Macro错误分析及处理

    最近测试以前的一个程序,一般都是打开以前写的程序修改参数直接测试 但是发现以前的编译后出现错误. 奇怪了,以前的出现都是调试好了的啊,一般都是没有错误的,迅速找问题 跳转到错误代码行 代码区域 Hea ...

  7. 使用fragment,Pad手机共用一套代码

    项目代码结构: 1:MainActivity.java package com.example.fgtest; import android.app.Activity; import android. ...

  8. 感觉tbceditor很不错,如果作者能坚持下来,非常非常看好啊

    感觉tbceditor很不错,如果作者能坚持下来,非常非常看好啊 你技术好,可以做个自用的IDE慢慢加功能 ,很方便的用这个控件,写个支持Delphi和html混编的编辑器,要不到2个小时

  9. zend server 和zend studio安装

    zend server安装完后需要更改一个xml文件. 用记事本打开D:\Program Files\Zend\ZendServer\etc\ZendEnablerConf.xml文件. 将 锘??x ...

  10. Contains Duplicate 解答

    Question Given an array of integers, find if the array contains any duplicates. Your function should ...