【发布时间】:2021-11-18 19:26:25
【问题描述】:
我有一个表格视图和集合视图来显示图像。垂直滚动的表格视图和水平滚动的集合视图。图像显示为设备的全屏。但是当我垂直滚动时,显示前一个单元格的一半,显示下一个单元格的一半。我使用 Table view constant is 0 来超级查看所有 4 个约束。
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return myTableView.frame.size.height;
}
返回单元格的高度,但即使这样也会导致同样的问题。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = self.myTableView.dequeueReusableCell(withIdentifier: "TableViewCell", for: indexPath) as! TableViewCell
return cell
}
此表格视图单元格包含集合视图
class TableViewCell: UITableViewCell,UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout{
func setUpCollectionView(){
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .horizontal
collectionView = UICollectionView(frame: .zero,collectionViewLayout: layout)
collectionView?.register(VideoCollectionViewCell.self, forCellWithReuseIdentifier: VideoCollectionViewCell.identifier)
collectionView?.isPagingEnabled = true
collectionView?.dataSource = self
collectionView?.delegate = self
self.contentView.addSubview(collectionView!)
collectionView?.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
collectionView!.topAnchor.constraint(equalTo: contentView.topAnchor),
collectionView!.bottomAnchor.constraint(equalTo: contentView.bottomAnchor),
collectionView!.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
collectionView!.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
])
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: self.frame.width, height: self.frame.height)
}
}
这是我的实现,我不希望图像显示为一半/一半。我正在尝试全屏显示。谁能告诉我为什么会这样?
【问题讨论】:
-
能否提供 gif 或图片以便我们更好地理解问题?
-
有一张来自 url 的图片,和我从我的设备上传的一样。它填充 imageView 的图像。
-
查看这个答案,希望对您有所帮助:stackoverflow.com/a/68622400/11974184
标签: ios swift uitableview uitableviewautomaticdimension