我的水平收藏视图只显示 2 张图像,每张图像占据屏幕的一半。我想防止滚动以使图像看起来像固定而没有移动。
// sizeForItemAt func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { if collectionView == self.topCollectionView{ let height = view.frame.size.height let width = view.frame.大小.宽度
return CGSize(width: width * (1/2), height: height * (1/2))
}
return CGSize()
}
// minimumLineSpacingForSectionAt
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat
{
if collectionView == self.topCollectionView{
return 3
}
return 3
}
// insetForSectionAt
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets
{
if collectionView == self.topCollectionView{
let sectionInset = UIEdgeInsets(top: 3, left: 4, bottom: 3, right: 4)
return sectionInset
}
let sectionInset2 = UIEdgeInsets(top: 3, left: 4, bottom: 3, right: 4)
return sectionInset2
}
}