4
我的集合视图从视图控制器视图的底部开始缩短。当用户向上滚动一下时,我希望收藏可以填充视图。当用户拉入反弹区域时,我希望它再次缩小。滚动时调整UICollectionView的大小
下面是我想使工作的代码(我认为应该工作):
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView == self.collectionView) {
CGFloat offsetY = self.collectionView.contentOffset.y;
if (offsetY > 20.0) {
[self setCollectionViewExpanded:YES];
} else if (offsetY < -10.0) {
[self setCollectionViewExpanded:NO];
}
}
}
- (void)setCollectionViewExpanded:(BOOL)expanded {
// avoid starting a do-nothing animation
BOOL currentlyExpanded = self.collectionView.frame.origin.y == 0.0;
if (expanded == currentlyExpanded) return;
// note: the collection view is the uppermost subview of the vc's view
// expanding to view bounds makes it cover every other view
CGRect newFrame = (expanded)? self.view.bounds : CGRectMake(0.0, 240.0, 320.0, self.view.bounds.size.height-240.0);
[UIView animateWithDuration:0.3 animations:^{
self.collectionView.frame = newFrame;
}];
}
但扩张发生后,细胞保持相对父视图,在相同的位置(仍靠近底部)并且收集视图停止响应平移触摸并且不发送进一步的didScroll通知。
我可以通过在动画完成块中执行reloadData来正确地重新定位内容,但滚动触摸无论如何都会停止工作。
一段时间后,我试着用表格视图(或另一种滚动视图)尝试类似的东西,并遇到类似的挂断。非常感谢,如果有人解决了这个问题...
谢谢。这是一个视图控制器(自我在我的代码片段中)与UIView(self.view)。其中一个子视图是我的集合视图(我相信你知道它是UIScrollView的子类)。 – danh 2013-04-01 16:11:05