UITableView 头部效果/放大/移动跟随效果

 [self.tableView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionOld|NSKeyValueObservingOptionNew context:nil];



- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{ CGPoint oldPoint = [change[@"old"] CGPointValue]; CGPoint newPoint = [change[@"new"] CGPointValue]; // NSLog(@"%@",change); CGFloat newY = newPoint.y; CGFloat oldY = oldPoint.y; if ( newY - oldY > 0) { //判断 self.imageView.y -= newY; self.tableView.y = self.imageView.bottom; [self.tableView setContentOffset:CGPointMake(0, 0)]; } else if ( newY - oldY < 0) { // self.imageView.y = self.imageView.y - newY; // if (self.imageView.y >= 0) { // self.imageView.y = 0; // } // self.tableView.y = self.imageView.bottom; self.imageView.y -= newY; self.tableView.y = self.imageView.bottom; [self.tableView setContentOffset:CGPointMake(0, 0)]; } }


https://github.com/yongliangP/YLSpringHeader

https://github.com/Cloudox/ScrollShowHeaderDemo

https://www.jianshu.com/p/8e4ed860d460

猜你喜欢

转载自www.cnblogs.com/daxueshan/p/10797417.html