Clambake for iPhone有一个回退按钮在所有的导航条上.这是一个简单的没有文字箭头.

实现一个自定义按钮是简单的.类似这个设置controller 的navigationItem一个leftBarButtonItem.

 - (void)viewDidLoad
{
self.navigationItem.leftBarButtonItem = [self backButton];
} - (UIBarButtonItem *)backButton
{
UIImage *image = [UIImage imageNamed:@"back_button"];
CGRect buttonFrame = CGRectMake(, , image.size.width, image.size.height); UIButton *button = [[UIButton alloc] initWithFrame:buttonFrame];
[button addTarget:self action:@selector(backButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[button setImage:[UIImage imageNamed:normalImage] forState:UIControlStateNormal]; UIBarButtonItem *item; = [[UIBarButtonItem alloc] initWithCustomView:button]; return item;
}

但是这样在iOS7上 pop手势交互就不好使了.我发现了一个轻松解决的办法.

通过我的beta测试者,我收到了很多关于pop手势的崩溃日志.

我发现在栈中推入一个controller后,快速向左平滑,将会引起崩溃.

换句话说,如果用户在推入还在进行的时候立即去点击返回.那么导航控制器就秀逗了.

我在调试日志里面发现这些:

nested pop animation can result in corrupted navigation bar

经过几个小时的奋斗和尝试,我发现可以缓解这个错误:

设置手势的delegate为这个导航控制器

就像Stuart Hall在他的帖子说的那样,分配了一个手势交互行为的委托在自定义按钮显示的时候.然后,当用户快速点击退出的时候,控制器因为手势发送了一个消息在本身已经被销毁的时候.

我的解决方案是简单的让NavigationController自己成为响应的接受者.最好用一个UINavigationController的子类.

 @interface CBNavigationController : UINavigationController <UIGestureRecognizerDelegate>
@end @implementation CBNavigationController - (void)viewDidLoad
{
__weak CBNavigationController *weakSelf = self; if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)])
{
self.interactivePopGestureRecognizer.delegate = weakSelf;
}
} @end

在转场/过渡的时候禁用 interactivePopGestureRecognizer

当用户在转场的时候触发一个后退手势,则各种事件又凑一块了.导航栈内又成了混乱的.我的解决办法是,转场效果的过程中禁用手势识别,当新的视图控制器加载完成后再启用.再次建议使用UINavigationController的子类操作.

 @interface CBNavigationController : UINavigationController <UINavigationControllerDelegate, UIGestureRecognizerDelegate>
@end @implementation CBNavigationController - (void)viewDidLoad
{
__weak CBNavigationController *weakSelf = self; if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)])
{
self.interactivePopGestureRecognizer.delegate = weakSelf;
self.delegate = weakSelf;
}
} // Hijack the push method to disable the gesture - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)])
self.interactivePopGestureRecognizer.enabled = NO; [super pushViewController:viewController animated:animated];
} #pragma mark UINavigationControllerDelegate - (void)navigationController:(UINavigationController *)navigationController
didShowViewController:(UIViewController *)viewController
animated:(BOOL)animate
{
// Enable the gesture again once the new controller is shown if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)])
self.interactivePopGestureRecognizer.enabled = YES;
} @end

iOS7自定义back按钮和pop交互手势的更多相关文章

  1. iOS 7 自定义Back按钮 与 Pop interactive gesture 问题

    1.自定义Back按钮 iOS中很多时候我们都会自定义返回按钮,也是一件easy的事,类似如下: // 返回按钮 1 - (void)showNavBackButton { UIButton *bac ...

  2. 【转】自定义iOS的Back按钮(backBarButtonItem)和pop交互手势(interactivepopgesturerecognizer) --- 不错

    原文网址:http://blog.csdn.net/joonsheng/article/details/41362499 序 说到自定义UINavigetionController的返回按钮,iOS7 ...

  3. 关于iOS自定义返回按钮右滑返回手势失效的解决:

    在viewDidLoad方法里面添加下面这一句代码即可 self.navigationController.interactivePopGestureRecognizer.delegate=(id)s ...

  4. ios7自定义返回按钮后,右滑返回功能失效解决方法

    -(void)viewWillAppear:(BOOL)animated{     [super viewWillAppear:animated];     //开启ios右滑返回     if ([ ...

  5. 第十三篇、Swift_Nav自定义返回按钮后或者隐藏导航栏,Pop返回手势失效的解决方法 Pop全局返回添加的方法

    边缘的pop返回手势: override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = UIColor.purple ...

  6. iOS开发之自定义导航栏返回按钮右滑返回手势失效的解决

    我相信针对每一个iOS开发者来说~除了根视图控制器外~所有的界面通过导航栏push过去的界面都是可以通过右滑来返回上一个界面~其实~在很多应用和APP中~用户已经习惯了这个功能~然而~作为开发者的我们 ...

  7. OC导航栏自定义返回按钮

    [iOS]让我们一次性解决导航栏的所有问题 在默认情况下,导航栏返回按钮长这个样子   导航栏默认返回按钮 导航栏左上角的返回按钮,其文本默认为上一个ViewController的标题,如果上一个Vi ...

  8. iOS学习—— UINavigationController的返回按钮与侧滑返回手势的研究

    侧滑返回手势是从iOS7开始增加的一个返回操作,经历了两年时间估计iPhone用户大部分都已经忽略了屏幕左上角那个碍眼的back按钮了.之前在网上搜过有关侧滑手势的技术博客,发现大多比较散乱,甚至有很 ...

  9. iOS 自定义返回按钮,保留系统滑动返回

    原文链接 自定义返回按钮保留系统滑动返回手势.gif 1.简介 使用苹果手机,最喜欢的就是用它的滑动返回.作为一个开发者,我们在编写很多页面的时候,总是会因为这样那样的原因使得系统的滑动返回不可用.使 ...

随机推荐

  1. Asp.net自定义控件开发任我行(2)-TagPrefix标签

    摘要 前面我们已经做了一个最简单的TextBox的马甲,此篇文章,我们来讲讲自定义控件的标签.大家可能看到了上一篇中拖放进来的代码是 <cc1:TextEdit ID="TextEdi ...

  2. 8、HTML DOM总结

    1.HTML DOM (文档对象模型) 当网页被加载时,浏览器会创建页面的文档对象模型(Document Object Model):HTML DOM 模型被构造为对象的树. 2.DOM 方法 < ...

  3. leetcode 【 Merge Sorted Array 】python 实现

    题目: Given two sorted integer arrays A and B, merge B into A as one sorted array. Note:You may assume ...

  4. Python+Selenium练习篇之15-在浏览器中新开一个tab

    本文介绍如selenium方法打开一个新的tab,我们知道在浏览器里,我们按住 ctrl+ t 就可以新打开一个tab.所以我们学习如何利用webdriver中send_key 的方法去触发ctrl+ ...

  5. Python-S9——Day100-Web前端框架之Vue

    01 课程简介: 02 let和const: 03 箭头函数: 04 对象的单体模式: 05 nodejs介绍和npm操作: 06 webpack.babel介绍和vue的第一个案例: 07 昨日内容 ...

  6. CentOS7 haproxy+keepalived实现高可用集群搭建

    一.搭建环境 CentOS7 64位 Keepalived 1.3.5 Haproxy 1.5.18 后端负载主机:192.168.166.21 192.168.166.22 两台节点上安装rabbi ...

  7. [转]Jupyter NoteBook 的快捷键使用指南

  8. Could not connect to Redis at 127.0.0.1:6379: Connection refused

    启动redis:  redis-server ../redis.conf redis启动成功后 执行命令行redis-cli报:Could not connect to Redis at 127.0. ...

  9. 并查集:按秩合并 $n$ 个点所得树高不超过 $\lfloor\log n \rfloor$

    用 $h_n$ 表示按秩合并 $n$ 个点所得树的最大高度. 有 $h_1 = 0, h_2 = 1, h_3 = 1, h_4 = 2, h_5 = 2, \dots$ 有如下地推: \[ h_n ...

  10. 分布式文件系统FastDFS集群部署

    1.源码开放下载地址:https://github.com/happyfish100 早期源码开放下载地址:https://sourceforge.net/projects/fastdfs/files ...