标签:
当tableview滚动时,动态计算view的高度,代码:
//背景view - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { contentOffsetY = scrollView.contentOffset.y; } - (void)scrollViewDidScroll:(UIScrollView *)scrollView { newContentOffsetY = scrollView.contentOffset.y; if (newContentOffsetY > oldContentOffsetY && oldContentOffsetY > contentOffsetY) { // 向上滚动 [self scrollToTop:scrollView]; } else if (newContentOffsetY < oldContentOffsetY && oldContentOffsetY < contentOffsetY) { // 向下滚动 [self scrollToBottom:scrollView]; }
//如果不做这步判断,快速拖动时,会出现闪一下的bug if (scrollView.dragging) { if ((scrollView.contentOffset.y - contentOffsetY) > 0.f) { [self scrollToTop:scrollView]; } else if ((contentOffsetY - scrollView.contentOffset.y) > 0.f) { [self scrollToBottom:scrollView]; } } } - (void)scrollToBottom:(UIScrollView *)scrollView { // 向下滚动 CGRect rect = self.bgView.frame; rect.size.height = (- scrollView.contentOffset.y); rect.origin.y = TOP_HEIGHT; self.bgView.frame = rect; } - (void)scrollToTop:(UIScrollView *)scrollView { // 向上滚动 CGRect rect = self.bgView.frame; rect.size.height = (- scrollView.contentOffset.y); rect.origin.y = TOP_HEIGHT; self.bgView.frame = rect; } - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate { oldContentOffsetY = scrollView.contentOffset.y; }
标签:
原文地址:http://www.cnblogs.com/markxiu/p/5486659.html