1. 完全透明的导航栏
完全透明的导航栏经常出现在首页、详情页、登录、个人中心等页面,以下是一些APP的例子,当页面向上滑动时再加上一些过渡效果,的确很吸引眼球,这种设计个人也是非常喜欢。
实现下图所示的效果:
方法如下:
//全透明,一般在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];
}
//恢复成默认,一般在viewWillDisappear
+ (void)createDefaultNavigationBar:(UIViewController *)sender
{
[sender.navigationController.navigationBar setBackgroundImage:nil
forBarMetrics:UIBarMetricsDefault];
}
自定义导航栏返回按钮:
#pragma mark -
#pragma mark - 自定义导航栏按钮 返回按钮 或者其他按钮
- (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左滑返回手势失效了的问题
self.navigationController.interactivePopGestureRecognizer.delegate = (id<UIGestureRecognizerDelegate>)self;
}
- (void)navCustomBackButtonPressed
{
[self.navigationController popViewControllerAnimated:YES];
}