标签:
#import "CBNavigationController.h" //手势返回 @interface CBNavigationController ()<UIGestureRecognizerDelegate, UINavigationControllerDelegate> @end @implementation CBNavigationController - (void)viewDidLoad { [super viewDidLoad]; __weak CBNavigationController *weakSelf = self; if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) { self.interactivePopGestureRecognizer.delegate = weakSelf; self.delegate = weakSelf; } } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; } // 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]; } //推出控制器 - (UIViewController *)popViewControllerAnimated:(BOOL)animated { if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) self.interactivePopGestureRecognizer.enabled = YES; return [super popViewControllerAnimated:animated]; } #pragma mark UINavigationControllerDelegate //已经显示了控制器 - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animate { //注意:这里当导航控制器只有一个viewcontroller的时候不能可以手势,否则奔溃 if(self.viewControllers.count > 1) { if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) self.interactivePopGestureRecognizer.enabled = YES; } else { if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) self.interactivePopGestureRecognizer.enabled = NO; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
navigationcontroller手势翻页和navigationbar
标签:
原文地址:http://www.cnblogs.com/apem/p/4584936.html