1. 完全透明的導(dǎo)航欄
完全透明的導(dǎo)航欄經(jīng)常出現(xiàn)在首頁(yè)椰憋、詳情頁(yè)厅克、登錄、個(gè)人中心等頁(yè)面橙依,以下是一些APP的例子证舟,當(dāng)頁(yè)面向上滑動(dòng)時(shí)再加上一些過(guò)渡效果,的確很吸引眼球窗骑,這種設(shè)計(jì)個(gè)人也是非常喜歡女责。
實(shí)現(xiàn)下圖所示的效果:
方法如下:
//全透明,一般在viewWillAppear
+ (void)createCompletelyTransparentNavigationBar:(UIViewController *)sender
{
[sender.navigationController.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
sender.navigationController.navigationBar.shadowImage = [UIImage new];
sender.navigationController.navigationBar.translucent = YES;
sender.navigationController.view.backgroundColor = [UIColor clearColor];
sender.navigationController.navigationBar.backgroundColor = [UIColor clearColor];
}
//恢復(fù)成默認(rèn)创译,一般在viewWillDisappear
+ (void)createDefaultNavigationBar:(UIViewController *)sender
{
[sender.navigationController.navigationBar setBackgroundImage:nil
forBarMetrics:UIBarMetricsDefault];
}
自定義導(dǎo)航欄返回按鈕:
#pragma mark -
#pragma mark - 自定義導(dǎo)航欄按鈕 返回按鈕 或者其他按鈕
- (void)createCustomNavigationBackOrOtherButton
{
UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
backBtn.frame = CGRectMake(0, 0, 32, 32);
[backBtn addTarget:self action:@selector(navCustomBackButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[backBtn setImage:[UIImage imageNamed:@"NavBackCustomImg"] forState:UIControlStateNormal];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
// self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"NavBackCustomImg"] style:UIBarButtonItemStyleBordered target:self action:@selector(navCustomBackButtonPressed)];
//解決自定義了leftBarbuttonItem左滑返回手勢(shì)失效了的問(wèn)題
self.navigationController.interactivePopGestureRecognizer.delegate = (id<UIGestureRecognizerDelegate>)self;
}
- (void)navCustomBackButtonPressed
{
[self.navigationController popViewControllerAnimated:YES];
}