UINavigationController侧滑滑动返回 卡死问题
UINavigationController滑动返回,有需要的朋友可以参考下。
最近做了UINavigationController的滑动返回(IOS7及以后系统默认支持的), 主要分成以下几步以及碰到的问题, 我这里做个总结:
*.首先说明个普遍碰到的问题
网上普遍看到说, 在UINavigationController下自定义leftBarButtonItem会导致滑动失效, 解决方案:http://blog.csdn.net/meegomeego/article/details/25879605
但我想告诉大家, 我也是自定义了leftBarButtonItem却没有碰到上述问题, 我是统一写了一个BaseViewController作为所有controller父类, 除了rootConrtoller, 这里不知为何, 有知道的可以留言.
排除上述原因, 下面介绍下怎么实现滑动:
1. 自定义UINavigationController(我写了个UIBaseNavigationController)以共用, 在ViewDidLoad里加入代码:
- (void)viewDidLoad
{
[super viewDidLoad]; /* UINavigationControllerDelegate */
self.delegate = self; / swipe gesture /
__weak typeof (self)weakSelf = self;
if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
// self.interactivePopGestureRecognizer.enabled = YES;
/* UIGestureRecognizerDelegate */
self.interactivePopGestureRecognizer.delegate = weakSelf;
}
}
这里是将interactivePopGestureRecognizer.delegate赋给self. 这样便可以实现滑动, 因为enabled默认是YES.
2. 在滑动过程中你会发现如果在pushViewController的动画过程中激活滑动手势会导致crash, 解决方案:
/ set gesture no when pushViewController /
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.interactivePopGestureRecognizer.enabled = NO;
} [super pushViewController:viewController animated:animated];
}
在push的时候关闭手势, 这样就不用担心会激活滑动
3. 自然, 在当你加载完成下一个viewController之后需要激活滑动手势:
/ set gesture yes when showViewController /
- (void)navigationController:(UINavigationController )navigationController didShowViewController:(UIViewController )viewController animated:(BOOL)animated
{
if ([navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
navigationController.interactivePopGestureRecognizer.enabled = YES;
}
}
4. 当然, 你还会发现一个问题:在rootController下滑动的时候, 在想push到下一个页面会没有反应, 界面卡死在那了, 所以还需要在上述方法中加入以下代码:
/ set gesture yes when showViewController /
- (void)navigationController:(UINavigationController )navigationController didShowViewController:(UIViewController )viewController animated:(BOOL)animated
{
if ([navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
navigationController.interactivePopGestureRecognizer.enabled = YES;
} / if rootViewController, set delegate nil /
if (navigationController.viewControllers.count == 1) {
navigationController.interactivePopGestureRecognizer.enabled = NO;
navigationController.interactivePopGestureRecognizer.delegate = nil;
}
}
在判断当前为rootController, 设置手势无效, 而且必须设置delegate为nil, 这样的话就可以解决卡死的问题了.
这样的话, 就可以完成navigationcontroller下的返回滑动了, 和微信一样一样滴~~~~~
UINavigationController侧滑滑动返回 卡死问题的更多相关文章
- iOS7下滑动返回与ScrollView共存二三事
[转载请注明出处] = =不是整篇复制就算注明出处了亲... iOS7下滑动返回与ScrollView共存二三事 [前情回顾] 去年的时候,写了这篇帖子iOS7滑动返回.文中提到,对于多页面结构的应用 ...
- UINavigationController实现全屏滑动返回功能
说明: UINavigationController默认在push出的控制器中都有边沿滑动返回功能,但是只能从屏幕左边滑才能返回,若从屏幕中间画并没有效果.下面实现全屏滑动功能. 探究: 系统默认能够 ...
- iOS开发——实用技术OC篇&8行代码教你搞定导航控制器全屏滑动返回效果
8行代码教你搞定导航控制器全屏滑动返回效果 前言 如果自定了导航控制器的自控制器的leftBarButtonItem,可能会引发边缘滑动pop效果的失灵,是由于 self.interactivePop ...
- iOS7上leftBarButtonItem无法实现滑动返回的完美解决方案
今天遇到了在iOS7上使用leftBarButtonItem却无法响应滑动返回事件的问题,一番谷歌,最后终于解决了,在这里把解决方案分享给大家. 在iOS7之前的系统,如果要自定义返回按钮,直接设置b ...
- iOS 如何设置导航的滑动返回手势, 和系统饿一样
iOS 7 滑动返回那些事儿 2014/05/17 Wei .entry-meta .entry-header 在智能机越来越普及,屏幕越做越大的当下,滑动返回手势已经成为了一个应用的标配功能,甚至可 ...
- iOS之手势滑动返回功能-b
iOS中如果不自定义UINavigationBar,通过手势向右滑是可以实现返回的,这时左边的标题文字提示的是上一个ViewController的标题,如果需要把文字改为简约风格,例如弄过箭头返回啥的 ...
- iOS6下实现滑动返回
[转载请注明出处] 之前在看iOS7滑动返回时,发现了一个iOS6 SDK下的第三方实现,今天偶然间发现了作者在其博客上对该实现的一些心得,读来深觉之前的思考太过肤浅,许多实际的问题没有考虑到.帖子链 ...
- 使用SlidingPaneLayout 实现仿微信的滑动返回
上周,公司的项目改版要求加上一个右滑返回上一个界面,于是就在网上找了一些开源库打算实现.但是在使用的时候遇见了许多的问题.试了两天用过 https://github.com/ikew0ng/Swipe ...
- 再谈iOS 7的手势滑动返回功能
本文转载至 http://blog.csdn.net/jasonblog/article/details/28282147 之前随手写过一篇<使用UIScreenEdgePanGestureR ...
随机推荐
- win7 加域开机自动登录域用户
解决办法:1.本地管理员帐户登录到本机.点击左下角的“开始”,在运行中输入“regedit”,点击确定 2.弹出“注册表编辑器”,找到下面的路径:[HKEY_LOCAL_MACHINE\SOFTWAR ...
- REST Security with JWT using Java and Spring Security
Security Security is the enemy of convenience, and vice versa. This statement is true for any system ...
- 这是我定位的Bug
https://github.com/danielgindi/ios-charts/issues/406
- 使用jquery的小记
随便写点 1.给span这种标签赋值 不能用$("#id").val("abc"); 因为这种标签没有value属性 而应该用$("#id" ...
- Maven教程(转载)
转载自:http://www.yiibai.com/maven/ Apache Maven是一个软件项目管理和综合工具.基于项目对象模型(POM)的概念,Maven可以从一个中心资料片管理项目构建,报 ...
- PHP检测用户名是否存在
reg.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www ...
- [转] git 常用命令
查看.添加.提交.删除.找回,重置修改文件 git help <command> # 显示command的help git show # 显示某次提交的内容 git show $id gi ...
- HDU 4900 NO ACM NO LIFE(概率+枚举+搜索)(2014 Multi-University Training Contest 4)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4900 Problem Description There is an old country and ...
- Codeforces Round #288 (Div. 2)
A. Pasha and Pixels 题意就是给一个n*m的矩阵,k次操作,一开始矩阵全白,一次操作可以染黑一个格子,问第几次操作可以使得矩阵中存在一个2*2的黑色矩阵.直接模拟即可 代码: ...
- jquery on 动态添加的元素,神奇的bug
$(document.body).on("click", ".comments-item .link-comment", function () { 平时用 d ...