func collectionVIEw(collectionVIEw: UICollectionVIEw,layout collectionVIEwLayout: UICollectionVIEwFlowLayout,insetForSectionAtIndex section: Int) -> UIEdgeInsets { let cellCount = Double(collectionVIEw.numberOfItems(inSection: section)) if let cell = collectionVIEw.cellForItem(at: IndexPath(row: 0,section: section)) { let cellWIDth = Double(cell.frame.size.wIDth) let totalCellWIDth = cellWIDth * cellCount let cellSpacing = Double(collectionVIEwLayout.minimumInteritemSpacing) let totalSpacingWIDth = cellSpacing * (cellCount - 1) let leftInset = (collectionVIEw.frame.wIDth - CGfloat(totalCellWIDth + totalSpacingWIDth)) / 2 let rightInset = leftInset return UIEdgeInsetsMake(0,leftInset,rightInset) } return collectionVIEw.layoutmargins}
我收到以下控制台错误,但我的单元格小于我的collectionVIEw,并且我将section insets和layout margin设置为0.
2017-03-30 11:25:14.624 Prep[92400:1862856] The behavior of the UICollectionVIEwFlowLayout is not defined because:
2017-03-30 11:25:14.624 Prep[92400:1862856] the item height must be less than the height of the UICollectionVIEw minus the section insets top and bottom values,minus the content insets top and bottom values.
2017-03-30 11:25:14.624 Prep[92400:1862856] The relevant UICollectionVIEwFlowLayout instance is,and it is attached to ; layer = ; contentOffset: {0,0}; contentSize: {0,68.5}> collection vIEw layout: .
2017-03-30 11:25:14.625 Prep[92400:1862856] Make a symbolic breakpoint at UICollectionVIEwFlowLayoutBreakForInvalIDSizes to catch this in the deBUGger.
cell height –> 42.0
协议
class OvervIEwVIEwController: UIVIEwController,UICollectionVIEwDelegate,UICollectionVIEwDataSource,UICollectionVIEwDelegateFlowLayout {@IBOutlet weak var vipCollectionVIEw: UICollectionVIEw!var hostedMeetingsArray: [String]?var vipArray: [Attendee]?class OvervIEwVIEwController: UIVIEwController,UICollectionVIEwDelegateFlowLayout {@IBOutlet weak var vipCollectionVIEw: UICollectionVIEw!var hostedMeetingsArray: [String]?var vipArray: [Attendee]?解决方法 好吧,没有调用insetForSectionAt的问题是你必须像这样实现它:
func collectionVIEw(_ collectionVIEw: UICollectionVIEw,layout collectionVIEwLayout: UICollectionVIEwLayout,insetForSectionAt section: Int) -> UIEdgeInsets { //access to minimumInteritemSpacing by casting to UICollectionVIEwFlowLayout let layout = collectionVIEwLayout as! UICollectionVIEwFlowLayout let spacing = layout.minimumInteritemSpacing return UIEdgeInsetsMake(0.5,0.5,0)}
看看UICollectionVIEwDelegateFlowLayout协议. insetForSectionAt声明如下:
@available(iOS 6.0,*)optional public func collectionVIEw(_ collectionVIEw: UICollectionVIEw,insetForSectionAt section: Int) -> UIEdgeInsets
所以你需要第一个可选参数来实现这个功能.
总结以上是内存溢出为你收集整理的swift – 为什么没有调用UICollectionView insetForSectionsAtIndex?全部内容,希望文章能够帮你解决swift – 为什么没有调用UICollectionView insetForSectionsAtIndex?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)