标签:ios uinavigationcontroll interactivepopgestur 滑动 返回
最近做了UINavigationController的滑动返回(IOS7及以后系统默认支持的), 主要分成以下几步以及碰到的问题, 我这里做个总结:网上普遍看到说, 在UINavigationController下自定义leftBarButtonItem会导致滑动失效, 解决方案:http://blog.csdn.net/meegomeego/article/details/25879605
但我想告诉大家, 我也是自定义了leftBarButtonItem却没有碰到上述问题, 我是统一写了一个BaseViewController作为所有controller父类, 除了rootConrtoller, 这里不知为何, 有知道的可以留言.
排除上述原因, 下面介绍下怎么实现滑动:
- (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; } }
/ 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]; }
/ set gesture yes when showViewController / - (void)navigationController:(UINavigationController )navigationController didShowViewController:(UIViewController )viewController animated:(BOOL)animated { if ([navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) { navigationController.interactivePopGestureRecognizer.enabled = YES; } }
/ 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; } }
这样的话, 就可以完成navigationcontroller下的返回滑动了, 和微信一样一样滴~~~~~
标签:ios uinavigationcontroll interactivepopgestur 滑动 返回
原文地址:http://blog.csdn.net/dexin5195/article/details/43965093