#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView == _tableView) {
DDLogVerbose(@"%f", scrollView.contentOffset.y);
if (_tableView.contentOffset.y >= _backgroundScrollView.height / 3.0 * 1.0) {
[UIView animateWithDuration:0.5 animations:^{
_tableView.frame = CGRectMake(0, self.originY + 40, kScreenWidth, kScreenHeight - 64);
_backgroundScrollView.frame = CGRectMake(0, self.originY - _backgroundScrollView.height + 40,
kScreenWidth, _backgroundScrollView.height);
}];
} else if (_tableView.contentOffset.y <= -44 && _backgroundScrollView.originY < self.originY) {
[UIView animateWithDuration:0.5 animations:^{
_backgroundScrollView.frame = CGRectMake(0, self.originY,
kScreenWidth,
_backgroundScrollView.height);
_tableView.frame = CGRectMake(0, _backgroundScrollView.bottomY,
kScreenWidth,
kScreenHeight - 64 - _backgroundScrollView.height);
}];
}
}
}
效果如下,超过一定范围会自动显示与隐藏