UICollectionView Class Reference

来源:互联网 发布:软件测试需要会什么 编辑:程序博客网 时间:2024/05/18 02:56

UICollectionView如图所示是一个容器控件。

1 Initializing a Collection View

/// 初始化public init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout)

2 Configuring the Collection View

// 管理管理weak public var delegate: UICollectionViewDelegate?// 数据源代理weak public var dataSource: UICollectionViewDataSource?// 背景Viewpublic var backgroundView: UIView?

3 Creating Collection View Cells

// 注册通过class创建cellpublic func registerClass(cellClass: AnyClass?, forCellWithReuseIdentifier identifier: String)// 注册通过xib创建cellpublic func registerNib(nib: UINib?, forCellWithReuseIdentifier identifier: String)// 注册通过class创建组头和组尾public func registerClass(viewClass: AnyClass?, forSupplementaryViewOfKind elementKind: String, withReuseIdentifier identifier: String)// 注册通过xib创建组头和组尾public func registerNib(nib: UINib?, forSupplementaryViewOfKind kind: String, withReuseIdentifier identifier: String)// 缓存队列获取cellpublic func dequeueReusableCellWithReuseIdentifier(identifier: String, forIndexPath indexPath: NSIndexPath) -> UICollectionViewCell// 缓存队列获取组头部组尾public func dequeueReusableSupplementaryViewOfKind(elementKind: String, withReuseIdentifier identifier: String, forIndexPath indexPath: NSIndexPath) -> UICollectionReusableView

4 Changing the Layout

// 界面item显示约束public var collectionViewLayout: UICollectionViewLayout// 动画设置UICollectionViewLayoutpublic func setCollectionViewLayout(layout: UICollectionViewLayout, animated: Bool)// 动画设置UICollectionViewLayout且有回调@available(iOS 7.0, *)public func setCollectionViewLayout(layout: UICollectionViewLayout, animated: Bool, completion: ((Bool) -> Void)?)// 使用一个中间过渡UI变化@available(iOS 7.0, *)public func startInteractiveTransitionToCollectionViewLayout(layout: UICollectionViewLayout, completion: UICollectionViewLayoutInteractiveTransitionCompletion?) -> UICollectionViewTransitionLayout// 完成过渡@available(iOS 7.0, *)public func finishInteractiveTransition()// 取消过渡@available(iOS 7.0, *)public func cancelInteractiveTransition()

5 Reloading Content

// 刷新所有显itempublic func reloadData()// 刷新组public func reloadSections(sections: NSIndexSet)// 刷新多个cellpublic func reloadItemsAtIndexPaths(indexPaths: [NSIndexPath])

6 Getting the State of the Collection View

// 显示多少组public func numberOfSections() -> Int// 每一组显示的item数量public func numberOfItemsInSection(section: Int) -> Int// 当前显示的cellpublic func visibleCells() -> [UICollectionViewCell]

7 Inserting, Moving, and Deleting Items

// 插入Itemspublic func insertItemsAtIndexPaths(indexPaths: [NSIndexPath])// 移除Itemspublic func deleteItemsAtIndexPaths(indexPaths: [NSIndexPath])// 移动Itemspublic func moveItemAtIndexPath(indexPath: NSIndexPath, toIndexPath newIndexPath: NSIndexPath)    

8 Inserting, Moving, and Deleting Sections

// 插入sectionspublic func insertSections(sections: NSIndexSet)// 移除sectionspublic func deleteSections(sections: NSIndexSet)// 移动sectionspublic func moveSection(section: Int, toSection newSection: Int)

9 Reordering Items Interactively

// 能否交互移动item@available(iOS 9.0, *)public func beginInteractiveMovementForItemAtIndexPath(indexPath: NSIndexPath) -> Bool// item移动到某个点@available(iOS 9.0, *)public func updateInteractiveMovementTargetPosition(targetPosition: CGPoint)// 结束移动@available(iOS 9.0, *)public func endInteractiveMovement()// 取消交互移动@available(iOS 9.0, *)public func cancelInteractiveMovement()

10 Managing the Selection

// 能否选中public var allowsSelection: Bool// 能否选中多个itempublic var allowsMultipleSelection: Bool    // 当前选中的itempublic func indexPathsForSelectedItems() -> [NSIndexPath]?// 选中itempublic func selectItemAtIndexPath(indexPath: NSIndexPath?, animated: Bool, scrollPosition: UICollectionViewScrollPosition)// 取消选中itempublic func deselectItemAtIndexPath(indexPath: NSIndexPath, animated: Bool)

11 Managing Focus

// 检查焦点是否应该返回上一个焦点索引@available(iOS 9.0, *)public var remembersLastFocusedIndexPath: Bool

12 Locating Items and Views in the Collection View

// 根据点获取对应显示的itempublic func indexPathForItemAtPoint(point: CGPoint) -> NSIndexPath?// 当前显示的itemspublic func indexPathsForVisibleItems() -> [NSIndexPath]// cell对应的位置public func indexPathForCell(cell: UICollectionViewCell) -> NSIndexPath?// 根据位置获取对应cellpublic func cellForItemAtIndexPath(indexPath: NSIndexPath) -> UICollectionViewCell?// 根据指定的标记获取对应的位置@available(iOS 9.0, *)public func indexPathsForVisibleSupplementaryElementsOfKind(elementKind: String) -> [NSIndexPath]// 获取对应的组头或组尾@available(iOS 9.0, *)public func supplementaryViewForElementKind(elementKind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView// 获取当前显示的组头或组尾@available(iOS 9.0, *)public func visibleSupplementaryViewsOfKind(elementKind: String) -> [UICollectionReusableView]

13 Getting Layout Information

// 获取item对应的约束public func layoutAttributesForItemAtIndexPath(indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes?// 获取组头或组尾对应的约束public func layoutAttributesForSupplementaryElementOfKind(kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes?

14 Scrolling an Item Into View

// 滚动到指定的itempublic func scrollToItemAtIndexPath(indexPath: NSIndexPath, atScrollPosition scrollPosition: UICollectionViewScrollPosition, animated: Bool)

15 Animating Multiple Changes to the Collection View

// 批处理执行insert/delete/reload/movepublic func performBatchUpdates(updates: (() -> Void)?, completion: ((Bool) -> Void)?)

 


Appendix

UICollectionView Class Reference

Revision History

时间 描述 2016-07-25 博文完成

CSDN:http://blog.csdn.net/y550918116j

GitHub:https://github.com/937447974

0 0
原创粉丝点击