1
我有一個'UICollectionView',我用它通過繼承子類UICollectionViewFlowLayout
一次一個地水平分頁多個項目。根據屏幕尺寸設置UICollectionViewFlowLayout的項目大小
爲此,我已經在兩邊都設置了插圖,並且有一個覆蓋的方法來使項目始終位於屏幕的中心。
然後有電池充滿整個屏幕,但我們只是一個和下一個細胞的提示在屏幕上是這樣的:
|-------------------|
|-| |-----------| |-|
|x| |xxxxxxxxxxx| |x|
|x| |xxxxxxxxxxx| |x|
|x| |xxxxxxxxxxx| |x|
|x| |xxxxxxxxxxx| |x|
|x| |xxxxxxxxxxx| |x|
|-| |-----------| |-|
|-------------------|
爲了有我設置的itemSize
上prepareLayout
:
override func awakeFromNib() {
let spacingConstant: CGFloat = 16.0
self.minimumLineSpacing = spacingConstant * 2
self.sectionInset = UIEdgeInsets(top: 30, left: spacingConstant * 3, bottom: 30, right: spacingConstant * 3)
self.scrollDirection = .Horizontal
}
override func prepareLayout() {
super.prepareLayout()
if let mySize = self.collectionView?.frame {
let size = CGSize(
width: mySize.width - self.sectionInset.right - self.sectionInset.left,
height: mySize.height - self.sectionInset.top - self.sectionInset.bottom
)
self.itemSize = size
}
}
但我不斷收到警告,itemSize必須小於視圖的高度減插入,這正是我在這裏做的。
the behavior of the UICollectionViewFlowLayout is not defined because:
the item height must be less than the height of the UICollectionView minus the section insets top and bottom values.
完成這件事的最佳方法是什麼?