转自 http://www.jianshu.com/p/ae5e72dbb8dd
UILabel *navTitleLabel = [BMFriendControlsTool friendTitleLabel];
self.navTitleLabel = navTitleLabel;
[self.navigationController.navigationBar addSubview:navTitleLabel];
navTitleLabel.backgroundColor = [UIColor clearColor];
navTitleLabel.frame = CGRectMake((SCREEN_WIDTH-200)*0.5, 44, 200, 44);
self.navigationController.navigationBar.layer.masksToBounds = YES;
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
CGFloat offsetY = scrollView.contentOffset.y;
CGFloat delta = offsetY - self.lastOffsetY;
NSLog(@"offsetY:%lf,,,delta:%lf",offsetY,delta);
NSLog(@"self.nav.frame:%@",NSStringFromCGRect(self.navTitleLabel.frame));
if (delta >= 30 && delta <= 70) {
self.navTitleLabel.y = 70-delta;
self.navTitleLabel.alpha = 1.f;
}else if (delta >= 70) {
self.navTitleLabel.y = 0;
}else if (delta >= 0) {
CGFloat alpha = delta-40 / (30);
alpha = MAX(alpha, 0.f);
alpha = MIN(alpha, 1.f);
self.navTitleLabel.alpha = alpha;
}
}