-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
if (scrollView==self.ActivityTableview) {
// NSLog(@"%f",scrollView.contentOffset.y);
CGFloat offsetY = scrollView.contentOffset.y;
if (scrollView.contentOffset.y>=-20 && scrollView.contentOffset.y<50) {
[self.navigationController.navigationBar setBackgroundColor:[UIColor colorWithRed:255/255.0f green:255/255.0f blue:255/255.0f alpha:offsetY*2/100]];
[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, nil]];
[self setStatusBarBackgroundColor:[UIColor colorWithRed:255/255.0f green:255/255.0f blue:255/255.0f alpha:offsetY*2/100]];
//NSLog(@"变色");
}else if (scrollView.contentOffset.y<-20){
[self.navigationController.navigationBar setBackgroundColor:[UIColor colorWithRed:226/255.0f green:67/255.0f blue:70/255.0f alpha:0.0]];
[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, nil]];
[self setStatusBarBackgroundColor:[UIColor colorWithRed:226/255.0f green:67/255.0f blue:70/255.0f alpha:0.0]];
}else{
[self.navigationController.navigationBar setBackgroundColor:[UIColor whiteColor]];
// [self.navigationController.navigationBar setTintColor:[UIColor blackColor]];
[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor], NSForegroundColorAttributeName, nil]];
[self setStatusBarBackgroundColor:[UIColor whiteColor]];
}
}
}
- (void)setStatusBarBackgroundColor:(UIColor *)color {
UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
statusBar.backgroundColor = color;
}
}
网友评论