我正在研究一个应用程序,其中,我有UITableView,并且在uitableview的每个单元中,我都有水平滚动的uicollectionview。
现在,我想要的是:当我向任何方向滚动一个collectionview时,我的表的所有其他collectionviews都应该沿着这个方向滚动。
我曾尝试使用scrollview委托,但它无法正常工作。
我陷入了这个问题。 我曾在互联网上看过,但还找不到任何东西。
需要帮助! 谢谢
I am working on an application in which, I have UITableView and in each cell of uitableview i have uicollectionview scrolling horizontally.
Now, What I want is that: When I scroll one collectionview in any direction then all other collectionviews of my table should scroll accordingly in that direction.
I have tried using scrollview delegates but it is not working properly.
I am stuck in this issue. I have looked on internet but could not found anything yet.
Help needed! Thanks
最满意答案
好的我已经检查了我的代码,我的工作是:我在屏幕的左侧有一个tableView,其余的是UIScrollView,在其中我在顶部有一个宽度等于collectionView.contentSize的视图.width,并在该视图下方,collectionView,其高度等于屏幕高度,宽度等于其contentSize.width。 之后,ScrollView只能水平滚动,而collectionView只能垂直滚动,所以,当你水平滚动时,tableView会停留,标题视图和集合会水平滚动,如果你垂直滚动,标题视图会保持不变,并且集合视图和tableView同时滚动(您必须链接它们的代表)。
这就是我在UIScrollViewDelegate中所做的
编译标记 - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView { if (scrollView == _scrollView) { if (scrollView.contentOffset.y > 0 || scrollView.contentOffset.y < 0 ) { scrollView.contentOffset = CGPointMake(scrollView.contentOffset.x, 0); } } else { _tableView.contentOffset = CGPointMake(0, scrollView.contentOffset.y); _collectionView.contentOffset = CGPointMake(0, scrollView.contentOffset.y); } }tableView的单元格的高度和collectionView的单元格的高度是相同的。
Ok I've checked my code, what I do was: I got a tableView on the left side of the screen, and on the rest a UIScrollView, inside it I had on the top a view which width is equal to the collectionView.contentSize.width, and below that view, the collectionView, with its height equal to the screen height, and its width equal to its contentSize.width. After that, the ScrollView only scrolls horizontally, and the collectionView only scrolls vertically, so, when you scroll horizontally, the tableView stays, and the header view and the collection scrolls horizontally, and if you scroll vertically the header view stays fix, and the collection view and the tableView scrolls at the same time (you have to link their delegates).
That's what I do in the UIScrollViewDelegate
pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView { if (scrollView == _scrollView) { if (scrollView.contentOffset.y > 0 || scrollView.contentOffset.y < 0 ) { scrollView.contentOffset = CGPointMake(scrollView.contentOffset.x, 0); } } else { _tableView.contentOffset = CGPointMake(0, scrollView.contentOffset.y); _collectionView.contentOffset = CGPointMake(0, scrollView.contentOffset.y); } }The height of the cells of the tableView and the height of the cells of the collectionView was the same.
更多推荐
发布评论