Closed yeahg-dev closed 2 years ago
따라서 제약으로 사이즈를 결정하도록함
// ScreenShotCollectionViewCell
private let screenShotView = UIImageView()
private func setConstraintOfScreenShotView() {
invalidateTranslateAutoResizingMasks(
of: [screenShotView])
NSLayoutConstraint.activate([
screenShotView.leadingAnchor.constraint(
equalTo: self.contentView.leadingAnchor),
screenShotView.topAnchor.constraint(
equalTo: self.contentView.topAnchor),
screenShotView.trailingAnchor.constraint(
equalTo: self.contentView.trailingAnchor),
screenShotView.bottomAnchor.constraint(
equalTo: self.contentView.bottomAnchor),
screenShotView.widthAnchor.constraint(equalToConstant: CGFloat(280)),
screenShotView.heightAnchor.constraint(equalToConstant: CGFloat(500))
])
}
group.interItemSpacing = .fixed(15)
section.interGroupSpacing
으로 spacing 구현
private func createLayout() -> UICollectionViewLayout {
let sectionProvider = { [weak self] (sectionIndex: Int, layoutEnvironment: NSCollectionLayoutEnvironment) -> NSCollectionLayoutSection? in
guard let sectionKind = AppDetailViewModel.Section(rawValue: sectionIndex) else { return nil }
let section: NSCollectionLayoutSection
if sectionKind == .summary {
...
} else if sectionKind == .screenshot {
let itemSize = NSCollectionLayoutSize(
widthDimension: .estimated(280),
heightDimension: .fractionalHeight(1.0))
let item = NSCollectionLayoutItem(layoutSize: itemSize)
let groupSize = NSCollectionLayoutSize(
widthDimension: .estimated(280),
heightDimension: .estimated(500))
let group = NSCollectionLayoutGroup.horizontal(
layoutSize: groupSize,
subitems: [item])
section = NSCollectionLayoutSection(group: group)
section.interGroupSpacing = 10
section.orthogonalScrollingBehavior = .groupPaging
} else if sectionKind == .descritption {
...
} else {
fatalError("Unknown section!")
}
return section
}
return UICollectionViewCompositionalLayout(sectionProvider: sectionProvider)
}
문제 상황
customCollectionViewCell을 만들 때, UIImageView의 사이즈를 상수로 설정했다.
Cell사이즈를 기반으로 CompositionalLayout의 item과 group사이즈를 계산하기 위해
.estimated()
프로퍼티로 dimension을 설정했다.