Ios 如何展开具有表视图的自定义集合视图单元格?
我正在尝试自动使collectionView单元格垂直展开,以显示单元格上的tableView 正在正确填充tableView,在设置Ios 如何展开具有表视图的自定义集合视图单元格?,ios,swift,uicollectionview,Ios,Swift,Uicollectionview,我正在尝试自动使collectionView单元格垂直展开,以显示单元格上的tableView 正在正确填充tableView,在设置cell.tableView.ishiden=false之后,我正在调用集合视图单元格上的reload Swift 4.2,Xcode 10.3 编辑:为了澄清我的问题,当我在单元格上显示/隐藏表格视图时,我尝试切换展开/折叠单元格(使用自动调整大小)。 collectionView flowLayout变量: // FlowLayout of the colle
cell.tableView.ishiden=false之后,我正在调用集合视图单元格上的reload
Swift 4.2,Xcode 10.3
编辑:为了澄清我的问题,当我在单元格上显示/隐藏表格视图时,我尝试切换展开/折叠单元格(使用自动调整大小)。
collectionView flowLayout变量:
// FlowLayout of the collectionView
var flowLayout: UICollectionViewFlowLayout {
return self.collectionView?.collectionViewLayout as! UICollectionViewFlowLayout
}
collectionView viewDidLoad():
collectionView单元:
override func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes {
setNeedsLayout()
layoutIfNeeded()
let size = contentView.systemLayoutSizeFitting(layoutAttributes.size)
var frame = layoutAttributes.frame
frame.size.height = ceil(size.height)
layoutAttributes.frame = frame
let autoLayoutAttributes = super.preferredLayoutAttributesFitting(layoutAttributes)
// Specify you want _full width_
let targetSize = CGSize(width: layoutAttributes.frame.width, height: 0)
// Calculate the size (height) using Auto Layout
let autoLayoutSize = contentView.systemLayoutSizeFitting(targetSize, withHorizontalFittingPriority: UILayoutPriority.required, verticalFittingPriority: UILayoutPriority.defaultLow)
let autoLayoutFrame = CGRect(origin: autoLayoutAttributes.frame.origin, size: autoLayoutSize)
// Assign the new size to the layout attributes
autoLayoutAttributes.frame = autoLayoutFrame
return autoLayoutAttributes
}
点击“显示表格视图”按钮时的collectionView单元格:
cell.tableView.isHidden = false
collectionView.reloadItems(at: [indexPath])
谢谢
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let cell = collectionView.cellForItem(at: indexPath) as! yourCell
if cell.tableView.isHidden {
return CGize(width: cellWidth, height:0)
}
return CGSize(width: tableViewWidth, height: TotalTableViewCellsHeight)
}
或
或
我在这里没有看到任何问题,您可以正确填充UICollectionViewCell,这不是您想要的吗?感谢您的回复,我在我的原始帖子中增加了一点清晰性:为了澄清我的问题,我正在尝试切换展开/折叠单元格(使用自动调整大小)当我在单元格上显示/隐藏tableView时。我在这里看不到任何问题,您可以正确填充UICollectionViewCell,这不是您想要的吗?感谢您的回复,我在我的原始帖子中增加了一点清晰性:为了澄清我的问题,我正在尝试切换展开/折叠单元格(使用自动调整大小)当我在单元格上显示/隐藏tableView时。
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let cell = collectionView.cellForItem(at: indexPath) as! yourCell
if cell.tableView.isHidden {
return CGize(width: cellWidth, height:0)
}
return CGSize(width: tableViewWidth, height: TotalTableViewCellsHeight)
}
@IBAction func showTableView(_ sender: Any) {
flowLayout.itemSize = CGSize(width: newCellWidth, height: newCellHeight)
}