KVO监听导航栏
监听tableView的偏移量改变导航栏的颜色
1 - (void)viewDidLoad { 2 [super viewDidLoad]; 3 // Do any additional setup after loading the view, typically from a nib. 4 self.automaticallyAdjustsScrollViewInsets = NO; 5 self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, [UIScreen mainScreen].bounds.size.width,[UIScreen mainScreen].bounds.size.height-64) style:(UITableViewStylePlain)]; 6 self.tableView.dataSource = self; 7 self.tableView.delegate = self; 8 [self.view addSubview:self.tableView]; 9 [self.tableView addObserver:self forKeyPath:@"contentOffset" options:(NSKeyValueObservingOptionNew) context:nil]; 10 } 11 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context 12 { 13 CGFloat offset = self.tableView.contentOffset.y; 14 NSLog(@"offset=%f",offset); 15 16 CGFloat delta = offset/64.f + 1.f; 17 delta = MAX(0, delta); 18 NSLog(@"delta=%f",delta); 19 self.navigationController.navigationBar.alpha = delta; 20 21 }
我的心愿是什么呢