見過很多項目,設(shè)置不同導(dǎo)航欄,有隱藏與顯示設(shè)置的,每個頁面有畫頁將要出現(xiàn),離開畫頁處理導(dǎo)航欄圖片文字顏色的。
工作年限,加班時間不會使你技術(shù)進步,只會讓你習慣垃圾代碼的寫法,記住垃圾代碼,抄來抄去垃圾代碼,不愿在改動垃圾代碼,多么可悲的大神啊
用到第三方 FDFullscreenPopGesture,思路,設(shè)置一個全局的導(dǎo)航欄背景或者圖片,title baritem顏色,不一樣的背景title一行隱藏全局的導(dǎo)航欄,在自己頁面寫個view模擬導(dǎo)航。
實際項目運用,顯示與隱藏各種切換未出任何異常。
比如有個CKKShareVC需要特別的導(dǎo)航欄。操作流程
一、當前頁面處理
- (void)viewDidLoad {
[super viewDidLoad];
self.fd_prefersNavigationBarHidden = YES;
}
二、基類導(dǎo)航處理
#pragma mark - life cycle
+ (void)initialize {
[[UINavigationBar appearance] setTranslucent:NO];
NSDictionary *titleAttributeDict = @{NSForegroundColorAttributeName:[UIColor whiteColor],
NSFontAttributeName:[UIFont systemFontOfSize:18.0]};
[[UINavigationBar appearance] setTitleTextAttributes:titleAttributeDict];
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"Main001"]
forBarPosition:UIBarPositionAny
barMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
// UIBarButtonItem
UIBarButtonItem *item=[UIBarButtonItem appearance];
item.tintColor = [UIColor whiteColor];
NSDictionary *itemAttributeDict= @{NSFontAttributeName:[UIFont systemFontOfSize:15],
NSForegroundColorAttributeName : [UIColor whiteColor]};
[item setTitleTextAttributes:itemAttributeDict forState:UIControlStateNormal];
// backItem 這里設(shè)置全局返回按鈕,不夠靈活,美工給的圖不到位的話,很難調(diào)整
// UIImage *originImage = [UIImage imageNamed:@"navback"];
// UIEdgeInsets insets = UIEdgeInsetsMake(0.0f, -10.0f, 0.0f, -10.0f);
// UIColor *fillColor = [UIColor clearColor];
// UIImage *backButtonImage = [originImage imageByInsetEdge:insets withColor:fillColor];
// [item setBackButtonBackgroundImage:[originImage resizableImageWithCapInsets:UIEdgeInsetsMake(0, 18, 0, 0) ]
// forState:UIControlStateNormal
// barMetrics:UIBarMetricsDefault];
// UIOffset minOffset =
// UIOffsetMake(NSIntegerMin, NSIntegerMin);
// [item setBackButtonTitlePositionAdjustment:minOffset
// forBarMetrics:UIBarMetricsDefault];
}
#pragma mark - view life cycle
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
self.delegate = self;
}
// 實現(xiàn)代理
#pragma mark - Private Methods
#pragma mark -
#pragma mark Whether need Navigation Bar Hidden
- (BOOL) needHiddenBarInViewController:(UIViewController *)viewController {
BOOL needHideNaivgaionBar = NO;
/// 這里設(shè)置CKKShareVC要隱藏狀態(tài)欄
if ([viewController isKindOfClass: NSClassFromString(@"CKKShareVC")]) {
needHideNaivgaionBar = YES;
}
return needHideNaivgaionBar;
}
#pragma mark - UINaivgationController Delegate
#pragma mark -
#pragma mark Will Show ViewController
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
// 在 NavigationController 的這個代理方法中, 設(shè)置導(dǎo)航欄的隱藏和顯示
[self setNavigationBarHidden: [self needHiddenBarInViewController: viewController]
animated: animated];
}