導(dǎo)航欄問題

導(dǎo)航欄技術(shù)參考文章:http://tech.glowing.com/cn/change-uinavigationbar-backgroundcolor-dynamically/

導(dǎo)航欄問題

導(dǎo)航欄錯亂http://www.itdecent.cn/p/e4448c24d900

1、設(shè)置導(dǎo)航欄背景色或者背景圖片時,會因?yàn)閷?dǎo)航欄默認(rèn)的透明度問題 跟原效果色不同。 如果設(shè)置透明度translucent 為no。 有些第三方的布局會受到影響(一般下移64)。
2、一級界面導(dǎo)航欄隱藏,二級界面顯示。當(dāng)pop回來的時候?qū)Ш綑跁?。解決辦法。在一級界面中,

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:animated];
}

-(void)viewWillDisappear:(BOOL)animated
{
    self.navigationController.navigationBarHidden = NO;
    [super viewWillDisappear:animated];
}

3、去除導(dǎo)航欄下方線

#define iOS10 ([[UIDevice currentDevice].systemVersion intValue]>=10?YES:NO)
- (void)viewWillAppear:(BOOL)animated{ 
       [super viewWillAppear:animated];               
       [self.navigationController.navigationBar.subviews enumerateObjectsUsingBlock:^(UIView *view, NSUInteger idx, BOOL *stop) {
      if (iOS10) { 
      //iOS10,改變了導(dǎo)航欄的私有接口為_UIBarBackground 
      if ([view isKindOfClass:NSClassFromString(@"_UIBarBackground")]) { 
        [view.subviews firstObject].hidden = YES; 
        } 
    }else{ 
          //iOS10之前使用的是_UINavigationBarBackground 
            if ([view isKindOfClass:NSClassFromString(@"_UINavigationBarBackground")]) { [view.subviews firstObject].hidden = YES;
                             }
                    }
          }];
}

精簡版:

- (void)viewWillAppear:(BOOL)animated{
          [super viewWillAppear:animated];           
         self.navigationController.navigationBar.subviews[0].subviews[0].hidden = YES;
     }

4、導(dǎo)航欄返回按鈕功能可以放在baseViewController中,iOS7之后系統(tǒng)提供了側(cè)滑手勢(interactivePopGestureRecognizer),即從屏幕左側(cè)邊緣滑起會pop回導(dǎo)航控制器棧的上個viewController。**不過如果你自定義了UINavigationViewController或者自定義了返回按鈕,系統(tǒng)自帶的側(cè)滑返回功能會失效??梢匀缦虏僮?方一:

self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;

方二:右滑返回功能可以去利用除系統(tǒng)屏幕邊緣滑動返回,

#import "ViewController.h"

@interface ViewController ()<UIGestureRecognizerDelegate>

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    id target = self.navigationController.interactivePopGestureRecognizer.delegate;

    // handleNavigationTransition:為系統(tǒng)私有API,即系統(tǒng)自帶側(cè)滑手勢的回調(diào)方法,我們在自己的手勢上直接用它的回調(diào)方法
    UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:target action:@selector(handleNavigationTransition:)];
    panGesture.delegate = self; // 設(shè)置手勢代理,攔截手勢觸發(fā)
    [self.view addGestureRecognizer:panGesture];

    // 一定要禁止系統(tǒng)自帶的滑動手勢
    self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
// 什么時候調(diào)用,每次觸發(fā)手勢之前都會詢問下代理方法,是否觸發(fā)
// 作用:攔截手勢觸發(fā)
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    // 當(dāng)當(dāng)前控制器是根控制器時,不可以側(cè)滑返回,所以不能使其觸發(fā)手勢
    if(self.navigationController.childViewControllers.count == 1)
    {
        return NO;
    }
    return YES;
}
@end

但此方法涉及私有API不知是否影響上架,詳見http://www.itdecent.cn/p/737924684695

標(biāo)簽欄TabBar

TabBar嵌套Nav時,進(jìn)行Push的時候隱藏TabBar的問題。(未完整待補(bǔ)充)
隱藏方式:
self.hidesBottomBarWhenPushed = YES;

將viewWillAppear里面的代碼更換成:
if (self.navigationController.viewControllers.count > 1) {
self.tabBarController.tabBar.hidden = YES;
}else {
self.tabBarController.tabBar.hidden = NO;
}

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

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

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