给每个页面添加手势,只需要统一设置不是根控制器的页面,都增加手势。需要自定义导航控制器

1.继承代理

@interface BSNavigationController ()<UIGestureRecognizerDelegate>

2.设置代理

- (void)viewDidLoad {
[super viewDidLoad]; // 设置pop手势代理
self.interactivePopGestureRecognizer.delegate = self; }

3.实现代理

#pragma mark - <UIGestureRecognizerDelegate>

/**
* push进来的控制器大于1个,手势有效
*/
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{ return self.viewControllers.count > ;
}

在开发过程中,经常会用到,需要关闭某个页面的手势返回功能。

// 禁用返回手势
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated]; // 禁用 返回手势
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
} // 开启手势
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated]; // 开启手势
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
}
}
// 导航栏返回
- (void)blackBtnClick
{
// 开启手势,有时只在(void)viewWillDisappear:(BOOL)animated开启,该根栏目下所有的手势都会失效
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
} [self.navigationController popToRootViewControllerAnimated:YES];
}

参考网站:http://blog.csdn.net/jasonblog/article/details/28282147

iOS UI进阶-6.0 手势的更多相关文章

  1. [iOS UI进阶 - 5.0] 手势解锁Demo

    A.需求 1.九宫格手势解锁 2.使用了绘图和手势事件   code source: https://github.com/hellovoidworld/GestureUnlockDemo     B ...

  2. [iOS UI进阶 - 3.0] 触摸事件的基本处理

    A.需要掌握和练习的 1.介绍事件类型2.通过按钮的事件处理引出view的事件处理3.响应者对象 --> UIResponder --> UIView4.view的拖拽* 实现触摸方法,打 ...

  3. iOS UI进阶-1.0 Quartz2D

    概述 Quartz 2D是一个二维绘图引擎,同时支持iOS和Mac系统.Quartz 2D能完成的工作: 绘制图形 : 线条\三角形\矩形\圆\弧等 绘制文字 绘制\生成图片(图像) 读取\生成PDF ...

  4. [iOS UI进阶 - 6.0] CALayer

    A.基本知识 1.需要掌握的 CALayer的基本属性 CALayer和UIView的关系 position和anchorPoint的作用   2.概念 在iOS中,你能看得见摸得着的东西基本上都是U ...

  5. [iOS UI进阶 - 2.0] 彩票Demo v1.0

    A.需求 1.模仿“网易彩票”做出有5个导航页面和相应功能的Demo 2.v1.0 版本搭建基本框架   code source:https://github.com/hellovoidworld/H ...

  6. iOS UI进阶-4.0 地图与定位

    在移动互联网时代,移动app能解决用户的很多生活琐事,比如 导航:去任意陌生的地方 周边:找餐馆.找酒店.找银行.找电影院   在上述应用中,都用到了地图和定位功能,在iOS开发中,要想加入这2大功能 ...

  7. [iOS UI进阶 - 3.2] 手势识别器UIGestureRecognizer

    A.系统提供的手势识别器   1.敲击手势 UITapGestureRecognizer numberOfTapsRequired: 敲击次数 numberOfTouchesRequired: 同时敲 ...

  8. [iOS UI进阶 - 4.0] 涂鸦app Demo

    A.需求 1.超简易画图,只有一种画笔 2.清屏功能 3.回退功能 4.保存功能 5.使用了cocos2D   code source: https://github.com/hellovoidwor ...

  9. iOS UI进阶-3.0 核心动画

    Core Animation是一组非常强大的动画处理API,使用它能做出非常炫丽的动画效果,而且往往是事半功倍,使用它需要先添加QuartzCore.framework和引入对应的框架<Quar ...

随机推荐

  1. hdu3374 String Problem【最小表示法】【exKMP】

    String Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  2. atoi函数的用法

    库函数原型: #inclue <stdlib.h> int atoi(const char *nptr); 用法:将字符串里的数字字符转化为整形数.返回整形值. 注意:转化时跳过前面的空格 ...

  3. 关于Java程序流程控制的整理(未完善)

  4. python-mysql数据库导表存excel后发邮件(实例2)

    需求:用户输入mysql数据库中某表名,将此表导入到excel中,将导出文件以邮件形式发出 设计思路: 1连接数据库 2读取表头(cur.description--获取表头,函数返回二维元组,采用列表 ...

  5. 子分区 复合分区 Subpartitioning

    https://dev.mysql.com/doc/refman/8.0/en/partitioning-subpartitions.html

  6. 使用c#反射实现接口可视化调试页面

    直接上代码,引用CommTools.dll.包括aspx显示页面和aspx.cs获取反射数据源代码 using System; using System.Collections.Generic; us ...

  7. [skill][graphviz] 到底用什么画图: graphviz/inkscape/yed

    官方教程文档:http://www.graphviz.org/pdf/dotguide.pdf 一:在文档里抄一个简单的例子 /home/tong/Src/copyright/onescorpion/ ...

  8. Flink – WindowedStream

    在WindowedStream上可以执行,如reduce,aggregate,min,max等操作 关键是要理解windowOperator对KVState的运用,因为window是用它来存储wind ...

  9. python知识点杂记2

    1. 如果已经有一个list或者tuple,要调用一个可变参数怎么办?2. >>> nums = [1, 2, 3]3. >>> calc(*nums)4. 14* ...

  10. pip list 和 pip freeze

    https://blog.csdn.net/vitaminc4/article/details/76576956 Pip’s documentation statespip     descripti ...