使用:
#import "UINavigationBar+Awesome.h"
#define NAVBAR_CHANGE_POINT 50
- (void)viewDidLoad {
[super viewDidLoad];
[self.navigationController.navigationBar lt_setBackgroundColor:[UIColor clearColor]];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController.navigationBar setShadowImage:[UIImage new]];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
// 从二级页面返回时,改变根据当前偏移量改变导航栏颜色。
UIColor * color = [UIColor colorWithRed:100/255.0 green:100/255.0 blue:100/255.0 alpha:1];
CGFloat offsetY = self.tableView.contentOffset.y;
if (offsetY > NAVBAR_CHANGE_POINT) {
CGFloat alpha = MIN(1, 1 - ((NAVBAR_CHANGE_POINT + 64 - offsetY) / 64));
[self.navigationController.navigationBar lt_setBackgroundColor:[color colorWithAlphaComponent:alpha]];
} else {
[self.navigationController.navigationBar lt_setBackgroundColor:[color colorWithAlphaComponent:0]];
}
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
// 到二级页面导航栏恢复默认设置
[self.navigationController.navigationBar lt_reset];
self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
self.navigationController.navigationBar.tintColor = nil;
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
}
网友评论