隱藏導航欄的兩種方法

1.下面這種隱藏導航欄? 本人在開發中使用時候發現 導航的透明設置NO? 才在push頁面沒有黑影閃現,但是在本頁面使用本隱藏導航欄的方法時候再次push 一個隱藏的導航欄 會存在黑影的閃現,由于在viewWillDisappear? 調用了 [self.navigationController setNavigationBarHidden:NO animated:animated]; 同時在viewWillAppear 調用[self.navigationController setNavigationBarHidden:YES animated:animated]; ?很短時間內連續調用這個兩個方法導致。

所以注意使用時的控制 ?。

- (void)viewWillAppear:(BOOL)animated{

? ? [super ?viewWillAppear:animated];

? ? [self.navigationController ?setNavigationBarHidden:YES animated:animated];

}

- (void)viewWillDisappear:(BOOL)animated{

? ?[super ?viewWillDisappear:animated];

? ?[self.navigationController ?setNavigationBarHidden:NO ?animated:animated];

}


2.后來本人使用 透明化導航欄 但是這里不會真正隱藏導航欄只是導航欄透明了而已,同時去除黑線,如果不是使用[self imageWithColor:[UIColor clearColor]? 而使用[[UIImage ?alloc]init] 那只是去除黑線

- (void)viewWillAppear:(BOOL)animated{

? ? ? [super ?viewWillAppear:animated];

? ? ? [self.navigationController.navigationBar? setBackgroundImage:[self imageWithColor:[UIColor clearColor]? forBarMetrics:UIBarMetricsDefault];

? ? ? [self.navigationController.navigationBar setShadowImage:[self ?imageWithColor:[UIColor? clearColor]]];

}

- (void)viewWillDisappear:(BOOL)animated{

? ? ? ? [super ? viewWillDisappear:animated];?

? ? ? ? [self.navigationController.navigationBar ? setBackgroundImage:nil ? ? ?forBarMetrics:UIBarMetricsDefault];

? ? ? ? [self.navigationController.navigationBar ? setShadowImage:nil];

}

- (UIImage*)imageWithColor:(UIColor*)color

{

? ?CGRect rect =CGRectMake(0.0f,0.0f,1.0f,1.0f);

? ?UIGraphicsBeginImageContext(rect.size);

? ?CGContextRef context =UIGraphicsGetCurrentContext();

? ?CGContextSetFillColorWithColor(context, [colorCGColor]);

? ?CGContextFillRect(context, rect);

? ?UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

? UIGraphicsEndImageContext();

? return image;

}

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容