首页 > 代码库 > BaseNavigationController自定义导航栏
BaseNavigationController自定义导航栏
#import <UIKit/UIKit.h>
@interface RCDNavigationViewController : UINavigationController<UIGestureRecognizerDelegate,UINavigationControllerDelegate>
@end
<style>p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #1d9421 } p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; min-height: 21.0px } p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #c91b13 } p.p4 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #3c828c } p.p5 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #c32275 } p.p6 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo } p.p7 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #3d1d81 } p.p8 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #703daa } p.p9 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #822e0e } p.p10 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "PingFang SC"; color: #1d9421 } span.s1 { } span.s2 { font: 18.0px "PingFang SC" } span.s3 { color: #822e0e } span.s4 { color: #c32275 } span.s5 { color: #000000 } span.s6 { color: #3d1d81 } span.s7 { color: #703daa } span.s8 { color: #6122ae } span.s9 { color: #0435ff } span.s10 { font: 18.0px Menlo; color: #000000 } span.s11 { font: 18.0px Menlo }</style>
// .m
#import "RCDNavigationViewController.h"
@interface RCDNavigationViewController ()
@end
@implementation RCDNavigationViewController
- (void)viewDidLoad {
[super viewDidLoad];
__weak RCDNavigationViewController *weakSelf = self;
if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.interactivePopGestureRecognizer.delegate = weakSelf;
self.delegate = weakSelf;
self.interactivePopGestureRecognizer.enabled = YES;
}
}
- (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;
}
}
//UIGestureRecognizerDelegate
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
if ([gestureRecognizer isEqual:self.interactivePopGestureRecognizer] &&
self.viewControllers.count > 1 &&
[self.visibleViewController isEqual:[self.viewControllers lastObject]]) {
//判断当导航堆栈中存在页面,并且 可见视图 如果不是导航堆栈中的最后一个视图时,就会屏蔽掉滑动返回的手势。此设置是为了避免页面滑动返回时因动画存在延迟所导致的卡死。
return YES;
} else {
return NO;
}
}
@end
BaseNavigationController自定义导航栏