1
X 셀을 반환하는 간단한 UICollectionViewController가 있습니다. 셀을 선택하면 특정 셀이 크기가 변경되고 다른 모든 셀이 그대로 유지되므로 높이가 커집니다. 이것을 어떻게 성취합니까? 당신은 sizeForItemAt
에서 indexPath
이 선택되어 있는지 확인할 수 있습니다선택한 UICollectionView 셀의 크기 변경
class HomeController: UICollectionViewController, UICollectionViewDelegateFlowLayout {
let cellId = "cellId"
override func viewDidLoad() {
super.viewDidLoad()
collectionView?.backgroundColor = UIColor(white: 0.90, alpha: 1.0)
collectionView?.register(PostCell.self, forCellWithReuseIdentifier: cellId)
collectionView?.showsVerticalScrollIndicator = false
collectionView?.alwaysBounceVertical = true
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 4
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath) as! PostCell
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let height = (view.frame.width) * 9/16
return CGSize(width: view.frame.width, height: height + 50 + 50)
}
}
사례를 제공해 주시겠습니까? 고맙습니다. –
지금 한 가지만 작업하십시오. – Callam
감사합니다. 정말 감사합니다. –