navigationcontroller手势翻页和navigationbar
一. 系统导航默认手势
#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
二. 导航栏的barStyle 和 translucent
iOS7之后由于navigationBar.translucent默认是YES,坐标零点默认在(0,0)点 当不透明的时候,零点坐标在(0,64);如果你想设置成透明的,而且还要零点从(0,64)开始,那就添加:self.edgesForExtendedLayout = UIRectEdgeNone;
translucent = NO, 零点从(0,64)开始, 如果想要零点从(0,0)点开始, 只需要设置: self.extendedLayoutIncludesOpaqueBars = YES;
@property(nonatomic,assign) BOOL extendedLayoutIncludesOpaqueBars NS_AVAILABLE_IOS(7_0); // Defaults to NO, but bars are translucent by default on 7_0.
@property(nonatomic,assign) BOOL automaticallyAdjustsScrollViewInsets NS_AVAILABLE_IOS(7_0); // Defaults to YES