可调整大小的 collectionview 单元格
Resizable collectionview cells
我如何创建一个集合视图,它会在单元格居中时调整其大小,就像上面图片中的那样?
您需要创建自定义 UICollectionViewLayout
,在其中根据单元格属性相对于集合视图中心的位置计算单元格属性。之后,您覆盖布局的 shouldInvalidateLayoutForBoundsChange(newBounds:)
方法:
override func shouldInvalidateLayoutForBoundsChange(newBounds: CGRect) -> Bool {
return true
}
此方法告诉您的集合视图,只要边界发生变化(即发生滚动),它就应该使其布局无效。
您可能会发现 this tutorial 很有用,除非您需要进行自己的比例计算而不是旋转。
您可以使用 UICollectionView 自定义布局来实现。
教程:
https://www.raywenderlich.com/164608/uicollectionview-custom-layout-tutorial-pinterest-2
或者您可以选择 GitHub
中非常有名的图书馆
iCaraousel:
https://github.com/nicklockwood/iCarousel
我如何创建一个集合视图,它会在单元格居中时调整其大小,就像上面图片中的那样?
您需要创建自定义 UICollectionViewLayout
,在其中根据单元格属性相对于集合视图中心的位置计算单元格属性。之后,您覆盖布局的 shouldInvalidateLayoutForBoundsChange(newBounds:)
方法:
override func shouldInvalidateLayoutForBoundsChange(newBounds: CGRect) -> Bool {
return true
}
此方法告诉您的集合视图,只要边界发生变化(即发生滚动),它就应该使其布局无效。
您可能会发现 this tutorial 很有用,除非您需要进行自己的比例计算而不是旋转。
您可以使用 UICollectionView 自定义布局来实现。
教程: https://www.raywenderlich.com/164608/uicollectionview-custom-layout-tutorial-pinterest-2
或者您可以选择 GitHub
中非常有名的图书馆iCaraousel: https://github.com/nicklockwood/iCarousel