带水平滚动的Swift UICollectionView,并将每个部分从左到右布置在自己的行上
我想让UICollectionView水平滚动,并从左到右在自己的行上布局每个部分 目前,带有水平滚动的my CollectionView每个部分都有一个垂直布局 理想情况下,我希望以下布局具有水平滚动: 所以我的问题是如何在UICollectionView上进行水平滚动,其中从左到右的每一水平行都排列在一行中。(见第二张图)每个部分将占用不同的行带水平滚动的Swift UICollectionView,并将每个部分从左到右布置在自己的行上,swift,xcode,uicollectionview,uicollectionviewlayout,Swift,Xcode,Uicollectionview,Uicollectionviewlayout,我想让UICollectionView水平滚动,并从左到右在自己的行上布局每个部分 目前,带有水平滚动的my CollectionView每个部分都有一个垂直布局 理想情况下,我希望以下布局具有水平滚动: 所以我的问题是如何在UICollectionView上进行水平滚动,其中从左到右的每一水平行都排列在一行中。(见第二张图)每个部分将占用不同的行 此外,每一行应同时水平滚动(如电子表格)。您必须将集合视图和表格视图结合起来,以便在UICollectionView上进行水平滚动,其中从左到右
此外,每一行应同时水平滚动(如电子表格)。您必须将集合视图和表格视图结合起来,以便在UICollectionView上进行水平滚动,其中从左到右的每一行都排列在一行中。每个部分将占据不同的一行
class DesignCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var lbltext: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
}
class DesignTableViewCell: UITableViewCell {
@IBOutlet weak var designCollectionView: UICollectionView!
var numberofScection = Int()
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
self.designCollectionView.register(UINib(nibName: "DesignCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "DesignCollectionViewCell")
self.designCollectionView.dataSource = self
self.designCollectionView.delegate = self
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .horizontal
self.designCollectionView.collectionViewLayout = layout
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
extension DesignTableViewCell: UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout{
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 7
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "DesignCollectionViewCell", for: indexPath) as! DesignCollectionViewCell
cell.lbltext.text = "section \(self.numberofScection) indexpath \(indexPath.row)"
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: 170, height: 100.0)
}
}
class ViewController: UIViewController {
@IBOutlet weak var designTableViewCell: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.designTableViewCell.register(UINib(nibName: "DesignTableViewCell", bundle: nil), forCellReuseIdentifier: "DesignTableViewCell")
self.designTableViewCell.dataSource = self
self.designTableViewCell.delegate = self
}
}
extension ViewController: UITableViewDataSource,UITableViewDelegate{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "DesignTableViewCell") as! DesignTableViewCell
cell.designCollectionView.reloadData()
cell.numberofScection = indexPath.row
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 110
}
}
到目前为止你试过什么?你能给我们提供一些代码吗?我尝试了一个解决方案,其中UITableVIew中的UITableViewCell的每一行都包含一个水平滚动的UICollectionView,但是我希望所有行同时水平滚动,而不是单独滚动,这样解决方案就不能满足我的需要。实际上,我创建了这个精确的解决方案,但是我希望所有行的所有水平滚动同时发生,而不是单个行。我很抱歉,因为我在问题中没有提到这一点。