【问题标题】:Scroll Horizontal on UITableViewCollection在 UITableViewCollection 上水平滚动
【发布时间】:2016-09-16 16:50:23
【问题描述】:

我正在使用 UICollectionView 来显示图像。 所以我以编程方式创建集合,并初始化布局以设置如下:

let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .Horizontal
howTo = UICollectionView(frame: self.view.bounds, collectionViewLayout: layout)
layout.scrollDirection = .Horizontal
self.howTo?.collectionViewLayout = layout
howTo!.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: "howToCell")

但滚动仍然是垂直的,我不知道为什么......我在创建集合之前和之后设置了水平以确保。 如果有人可以帮忙

非常感谢

【问题讨论】:

    标签: ios swift scroll uicollectionview


    【解决方案1】:

    您检查过您的内容大小吗? iOS 中的滚动视图仅在有要滚动到的内容的方向上滚动。尝试使集合视图大于水平视图,使用

    let frame = CGRectMake(0, 0, self.view.bounds.width * 2, self.view.bounds.height) howTo = UICollectionView(frame: frame, collectionViewLayout: layout)

    您应该会发现您的视图水平滚动。

    Make sure to take a look at Apple's scroll view docs

    【讨论】:

    • 我只是尝试了您的解决方案,但也没有用。我会复制/粘贴代码给你,也许你能说出来。 howTo = UICollectionView(frame: self.view.bounds, collectionViewLayout: layout) layout.scrollDirection = .Horizo​​ntal self.howTo?.collectionViewLayout = layout self.view.addSubview(howTo!) howTo!.snp_makeConstraints { (make) -> Void在 make.top.equalTo(readMoreText.snp_bottom).offset(15) make.leading.equalTo(self.view).offset(5) make.trailing.equalTo(self.view).offset(-5) make.height .equalTo(115) }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-23
    • 2011-07-10
    • 1970-01-01
    • 1970-01-01
    • 2016-03-14
    • 1970-01-01
    • 2016-06-26
    相关资源
    最近更新 更多