iOS7自定义back按钮和pop交互手势
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交互手势的更多相关文章
- iOS 7 自定义Back按钮 与 Pop interactive gesture 问题
1.自定义Back按钮 iOS中很多时候我们都会自定义返回按钮,也是一件easy的事,类似如下: // 返回按钮 1 - (void)showNavBackButton { UIButton *bac ...
- 【转】自定义iOS的Back按钮(backBarButtonItem)和pop交互手势(interactivepopgesturerecognizer) --- 不错
原文网址:http://blog.csdn.net/joonsheng/article/details/41362499 序 说到自定义UINavigetionController的返回按钮,iOS7 ...
- 关于iOS自定义返回按钮右滑返回手势失效的解决:
在viewDidLoad方法里面添加下面这一句代码即可 self.navigationController.interactivePopGestureRecognizer.delegate=(id)s ...
- ios7自定义返回按钮后,右滑返回功能失效解决方法
-(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; //开启ios右滑返回 if ([ ...
- 第十三篇、Swift_Nav自定义返回按钮后或者隐藏导航栏,Pop返回手势失效的解决方法 Pop全局返回添加的方法
边缘的pop返回手势: override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = UIColor.purple ...
- iOS开发之自定义导航栏返回按钮右滑返回手势失效的解决
我相信针对每一个iOS开发者来说~除了根视图控制器外~所有的界面通过导航栏push过去的界面都是可以通过右滑来返回上一个界面~其实~在很多应用和APP中~用户已经习惯了这个功能~然而~作为开发者的我们 ...
- OC导航栏自定义返回按钮
[iOS]让我们一次性解决导航栏的所有问题 在默认情况下,导航栏返回按钮长这个样子 导航栏默认返回按钮 导航栏左上角的返回按钮,其文本默认为上一个ViewController的标题,如果上一个Vi ...
- iOS学习—— UINavigationController的返回按钮与侧滑返回手势的研究
侧滑返回手势是从iOS7开始增加的一个返回操作,经历了两年时间估计iPhone用户大部分都已经忽略了屏幕左上角那个碍眼的back按钮了.之前在网上搜过有关侧滑手势的技术博客,发现大多比较散乱,甚至有很 ...
- iOS 自定义返回按钮,保留系统滑动返回
原文链接 自定义返回按钮保留系统滑动返回手势.gif 1.简介 使用苹果手机,最喜欢的就是用它的滑动返回.作为一个开发者,我们在编写很多页面的时候,总是会因为这样那样的原因使得系统的滑动返回不可用.使 ...
随机推荐
- Day24&25&26&27:HTML+CSS
1.网页得三大组成:HTML(标签.皮影的小人) \CSS(布局,皮影的装束) \JS(动作,皮影的操纵者) 2.HTML目录树 3.HTML-标签 成对<>组成,不区分大小写,自闭合标签 ...
- luogu3810 【模板】三维偏序(陌上花开)
ref1 ref2 ref3 ref4 #include <algorithm> #include <iostream> #include <cstdio> usi ...
- php和js中数组的总结
php中数组的表示方法:array()或者[] js中数组的表示方法:new array()或者[] 一.php中初始化命名数组 在PHP中声明数组的方式主要有两种:一是应用array()函数声明 ...
- IOS开发---菜鸟学习之路--(六)-UITableView几个方法的使用说明
对于UITableView的基础使用我这边就不做重复介绍了 我重点就来介绍下如何实现大部分新闻的界面.也就是第一条记录显示大图片下面加一段文字说明 然后剩下来的内容全部显示为文字图片的格式 其实要做到 ...
- leetcode 【 Swap Nodes in Pairs 】python 实现
题目: Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1-> ...
- leetcode 【 Reorder List 】python 实现
题目: Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do ...
- Python学习-day14-CSS
前端二:CSS CSS: 一:介绍:学名层叠样式表(Cading Style Sheets)是一种用来表现HTML或者XML等文件的样式的计算机语言.让HTML和XML看起来更加美观. 语法:&l ...
- Uncaught TypeError: Cannot read property of undefined In JavaScript
当脚本遇到未初始化的变量或对象时,通常会抛出如上图所示的错误. Decription 'Undefined'是全局对象的属性.如果没有为变量赋值,则为'undefined'类型.当求值变量没有任何赋值 ...
- tomcat 服务不支持 chkconfig 以及其他服务不能添加到开机启动时的操作
在安装完tomcat后想添加的开机自启动的操作,但是报错tomcat 服务不支持 chkconfig,后来在 /etc/init.d/tomcat中的#!/bin/bash后添加上#chkconfi ...
- vue-cli 脚手架分析
Vue-cli 一.安装vue-cli 安装vue-cli的前提是你已经安装了npm,安装npm你可以直接下载node的安装包进行安装.你可以在命令行工具里输入npm -v 检测你是否安装了npm和 ...