- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
//将状态栏内容颜色设置为白色(写在这里避免子界面返回到主界面时状态栏的颜色由黑色变成白色的变化效果)
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
[self.navigationController setNavigationBarHidden:YES animated:NO];
UIView *navView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WJScreenWidth, 64)];
navView.backgroundColor = [UIColor clearColor];
UILabel *navTitle = [[UILabel alloc] init];
self.navTitle = navTitle;
navTitle.hidden = YES;
navTitle.size = CGSizeMake(40, 20);
navTitle.center = navView.center;
navTitle.text = @"首页";
navTitle.font = [UIFont systemFontOfSize:18];
[navTitle setTextColor:WJRGBAColor(68, 79, 102, 1)];
navTitle.center = navView.center;
[navView addSubview:navTitle];
self.navView = navView;
[self.view insertSubview:navView atIndex:[self.view.subviews count]];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
float alpha = 1 - (64 - scrollView.contentOffset.y) / 64;
self.navView.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:alpha > 1 ? 1 : alpha];
if (scrollView.contentOffset.y > 0) {
self.navTitle.hidden = NO;
} else {
self.navTitle.hidden = YES;
}
if (scrollView.contentOffset.y >= 64) {
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
} else {
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
}
}