思路: 透视图不是放在tableView上面,而是放在控制器的view面,当tablView滚动的时候
透视图就跟着tablView滚动,(通过记录上次偏移量和当前偏移量来实现, tableView滚动多少,头视图就滚动多少),然后限制一下透视的的两个边界位置即可,通过MIN和MAX实现,同时,为了实现性能的优化,在超出临界值之后,就不再设置frame
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{if (scrollView.contentOffset.y > self.lastOffset && CGRectGetMinY(self.headerView.frame) <= 50) {self.lastOffset = scrollView.contentOffset.y;return;}if (scrollView.contentOffset.y < self.lastOffset && CGRectGetMinY(self.headerView.frame) >= 100) {self.lastOffset = scrollView.contentOffset.y;return;}CGRect rect = self.headerView.frame;CGPoint orign = rect.origin;orign.y -=(scrollView.contentOffset.y - self.lastOffset);orign.y = MIN(100, MAX(50, orign.y));rect.origin = orign;self.headerView.frame = rect;self.lastOffset = scrollView.contentOffset.y;
}