使用一个collectionview IOS滚动多个UICollectionView [英] Scroll Multiple UICollectionView with one collectionview IOS

查看:144
本文介绍了使用一个collectionview IOS滚动多个UICollectionView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,其中,我有UITableView,在uitableview的每个单元格中,我都有uicollectionview水平滚动。

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.

我尝试使用scrollview委托,但它无法正常工作。

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.

需要帮助!谢谢

推荐答案

好的我已经检查了我的代码,我的工作是:我在屏幕的左侧有一个tableView在其余的UIScrollView中,我在其顶部有一个宽度等于collectionView.contentSize.width的视图,在该视图下方,collectionView,其高度等于屏幕高度,其宽度相等到它的contentSize.width。之后,ScrollView只能水平滚动,而collectionView只能垂直滚动,所以,当你水平滚动时,tableView会停留,标题视图和集合会水平滚动,如果你垂直滚动,标题视图会保持不变,并且集合视图和tableView同时滚动(你必须链接他们的代表)。

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).

这就是我在UIScrollViewDelegate中所做的事情

That's what I do in the 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的单元格是相同的。

The height of the cells of the tableView and the height of the cells of the collectionView was the same.

这篇关于使用一个collectionview IOS滚动多个UICollectionView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆