我想以某种方式选择我的cellItem来增加一点大小,这与其他方法有所不同。实际上大小相同,但是一个选择比另一个高一个。这与布局有关吗?有什么方法吗?还是情节提要?
我附上了一些照片,以查看到目前为止我的工作以及应该做的事情。
应该如何
现在怎么样。
最佳答案
请参见下面的代码
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "TableCollectionViewCell", for: indexPath) as! TableCollectionViewCell
if cell.isSelected == true{
self.changeSelectedCellFrame(cell)
}
else
{
self.changeDeselectedCellFrame(cell)
}
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let cell = collectionView.cellForItem(at: indexPath) as! TableCollectionViewCell
self.changeSelectedCellFrame(cell)
}
func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
if let cell = collectionView.cellForItem(at: indexPath) as?TableCollectionViewCell
{
self.changeDeselectedCellFrame(cell)
}
}
func changeSelectedCellFrame(_ cell:TableCollectionViewCell) {
cell.layoutIfNeeded()
cell.viewTopConstraint.constant = 0
cell.viewBottomConstraint.constant = 20
cell.layoutIfNeeded()
}
func changeDeselectedCellFrame(_ cell:TableCollectionViewCell) {
cell.layoutIfNeeded()
cell.viewTopConstraint.constant = 10
cell.viewBottomConstraint.constant = 10
cell.layoutIfNeeded()
}
它会显示出与您预期相同的效果。
关于ios - 如何修改所选CollectionViewItem的大小,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47920988/