ios侧滑返回:完美解决 interactivePopGestureRecognizer 卡住的
来源:互联网 发布:qq群群发软件 编辑:程序博客网 时间:2024/04/28 20:15
苹果一直都在人机交互中尽力做到极致,在iOS7中,新增加了一个小小的功能,也就是这个api:self.navigationController.interactivePopGestureRec
这个api功能就是在NavigationController堆栈内的UIViewController可以支持右滑手势,也就是不用点击右上角的返回按钮,轻轻在屏幕左边一
滑,屏幕就会返回,随着ios设备屏幕的增大,这个小功能让手指短,拇指大和手残人士看到了福音。
这个功能是好,但是经常我们会有需求定制返回按钮,如果手动定制了返回按钮,这个功能将会失效,也就是自定义了navigationItem的leftBarButtonItem,那么这个手势就会失效。解决方法找到两种
有更多方法以后继续补充,这里可以根据自己需要进行选择,如果只是简单定制了返回按钮,第一种最简单,一句代码搞定。
interactivePopGestureRecognizer
是iOS7推出的解决VeiwController
滑动后退的新功能,虽然很实用,但是坑也很多啊(比如在rootViewcontroller下,使用侧滑返回手势,可能就卡住了),这里给出如何完美解决interactivePopGestureRecognizer
卡住的问题.
当然我们要自定义UINavigationController来解决这个问题:
#import "MMNavController.h"@interface MMNavController (){ }@end@implementation MMNavController- (id)initWithRootViewController:(UIViewController *)rootViewController{ self = [super initWithRootViewController:rootViewController]; if (self) { // Custom initialization } return self;}- (void)viewDidLoad{ __weak MMNavController *weakSelf = self; if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) { self.interactivePopGestureRecognizer.delegate = weakSelf; self.delegate = weakSelf; } }- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{ if ( [self respondsToSelector:@selector(interactivePopGestureRecognizer)] animated == YES ) { self.interactivePopGestureRecognizer.enabled = NO; } [super pushViewController:viewController animated:animated]; }- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated{ if ( [self respondsToSelector:@selector(interactivePopGestureRecognizer)] animated == YES ) { self.interactivePopGestureRecognizer.enabled = NO; } return [super popToRootViewControllerAnimated:animated]; }- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated {
if( [self respondsToSelector:@selector(interactivePopGestureRecognizer)] ) {
self.interactivePopGestureRecognizer.enabled = NO;
}
return [super popToViewController:viewController animated:animated]; }
#pragma mark UINavigationControllerDelegate
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController
animated:(BOOL)animate {
if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)])
{ self.interactivePopGestureRecognizer.enabled = YES; }
}
-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
if ( gestureRecognizer ==self.interactivePopGestureRecognizer ) {
if ( self.viewControllers.count 2 || self.visibleViewController == [self.viewControllers objectAtIndex:0] )
{ return NO; }
} return YES;
} @end
- ios侧滑返回:完美解决 interactivePopGestureRecognizer 卡住的
- iOS 完美解决iOS7 interactivePopGestureRecognizer 手势冲突
- iOS rootViewController侧滑返回卡住的解决方法
- 侧滑手势ios 关于interactivePopGestureRecognizer
- ios -- swift -- 侧滑返回时 页面卡住不动
- iOS---interactivePopGestureRecognizer
- 右滑返回上一级interactivePopGestureRecognizer
- interactivePopGestureRecognizer 完美使用
- ios中interactivePopGestureRecognizer的问题解决方法
- interactivePopGestureRecognizer ,右滑返回,自定义返回,多个tab
- 右滑动 返回 interactivePopGestureRecognizer
- ios 自定义返回按钮侧滑失效完美解决方案
- iOS 8 完美禁止右滑返回
- 解决Custom backBarButtonItem 后 interactivePopGestureRecognizer失效的问题
- 关于 ios 7.0启用的UINavgationViewController的interactivePopGestureRecognizer手势
- iOS7 手势滑动返回 interactivePopGestureRecognizer
- IOS7 自定义手势返回 interactivePopGestureRecognizer
- interactivePopGestureRecognizer返回时消息传递
- CNN卷积神经网络
- The Future of Real-Time SLAM and "Deep Learning vs SLAM" 深度学习与slam
- POJ2386水洼问题 优先深度搜索
- gerrit 使用中踩过的小坑
- python学习:装饰器,*args **kwargs
- ios侧滑返回:完美解决 interactivePopGestureRecognizer 卡住的
- 一个检查单词个数的程序
- Builder模式
- 使用基于ThinkPHP3.2.3的ThinkAdmin创建手机电脑通用的表白墙(五)墙实现
- 蓝桥 历届试题 兰顿蚂蚁
- Swift 基础学习(指定构造方法和便利构造方法)
- 原生javascript的ajax
- QML中按钮的各个属性
- 视频刻录