#pragma mark - 实现代理方法 UINavigationBarDelegate 改变导航栏的颜色等功能
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
UIImage *image = [UIImage imageNamed:@"128"];
[self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
UIView *view = self.navigationController.navigationBar.subviews[0];
if (_tableView.contentOffset.y <= - 64) {
self.navigationController.navigationBar.translucent = YES;
view.alpha = 0;
} else if(_tableView.contentOffset.y > - 64 && _tableView.contentOffset.y <= 0) {
self.navigationController.navigationBar.translucent = YES;
view.alpha = (64 - fabs(_tableView.contentOffset.y)) / 200.0f;//绝对值
} else {
view.alpha = (_tableView.contentOffset.y + 128) / 200.0f;
if (view.alpha >= 1) {
self.navigationController.navigationBar.translucent = NO;
}
}
DLog(@"%f", _tableView.contentOffset.y);
}