iOS導(dǎo)航欄最佳實踐

見過很多項目,設(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];
}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,366評論 25 708
  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 15,839評論 4 61
  • 在外漂泊多年,打過工,風餐露宿過,經(jīng)營過小型美容店,帶過營銷團隊,創(chuàng)辦過自己的公司,手上同時經(jīng)營過三個項目,參加各...
    君鈺AI茶事閱讀 478評論 0 2
  • 我們前端的少不了和后臺的交互。如果我們只會前端,后臺的知識不是很懂的時候就交互的時候就會出現(xiàn)很多問題。當我們通過接...
    奇董閱讀 27,587評論 14 46

友情鏈接更多精彩內(nèi)容