1120 - iOS之UICollectionViewDelegate 协议

Protocol

UICollectionViewDelegate

--The UICollectionViewDelegate protocol defines methods that allow you to manage the selection and highlighting of items in a collection view and to perform actions on those items. The methods of this protocol are all optional.

     这个协议里面的所有方法都是可选的,这个协议里面的方法是用来管理items的选中状态、高亮状态以及在这个item上执行动作。

Inherits From

UIScrollViewDelegate             --继承于UIScrollViewDelegate

     

Declaration --声明

protocol UICollectionViewDelegate

Overview -- 概览

--Many methods of this protocol take NSIndexPath objects as parameters. To support collection views, UIKit declares a category on NSIndexPath that enables you to get the represented item index and section index, and to construct new index path objects from item and index values.

      这个协议里面的很多方法都是以NSIndexPath对象作为参数,所以对象里面有一个类别(拓展)是用来获取当前展示的items和section的index的,并且也可以从item上创建新的NSIndexPath实例

--Because items are located within their sections, you usually must evaluate the section index number before you can identify the item by its index number.

       先估算section的index,才可以计算items的index

--When configuring the collection view object, assign your delegate object to its delegate property. For more information, see UICollectionView.

       在配置collection view对象之前,你要先给collection view的delegate属性赋值

Topics -- 专题

Managing the Selected Cells -- 管理和选择cell

 

Changing the Appearance of Selected and Highlighted Cells                            --示例代码,改变cell的选中和高亮状态

--Provide visual feedback to the user about the state of a cell and the transition between states.

    cell之间的状态以及状态之间的转换示例

 

Selecting Multiple Items with a Two-Finger Pan Gesture                        --示例代码:双手指手势选中多个cell

--Accelerate user selection of multiple items using the multiselect gesture on table and collection views.

   

func collectionView(UICollectionView, shouldSelectItemAt: IndexPath) -> Bool

                                                                                                                               --方法:(客户交互时)断定某item是否应该被选中

--Asks the delegate if the specified item should be selected.

 

func collectionView(UICollectionView, didSelectItemAt: IndexPath)

                                                                                                                      --方法:在这里配置已经被选中的items

--Tells the delegate that the item at the specified index path was selected.

 

func collectionView(UICollectionView, shouldDeselectItemAt: IndexPath) -> Bool

                                                                                                                      --方法:(客户交互)断定某item是否应该撤销选中

--Asks the delegate if the specified item should be deselected.

 

func collectionView(UICollectionView, didDeselectItemAt: IndexPath)

                                                                                                                      --方法:(客户交互时)在这里配置被取消选中的item

--Tells the delegate that the item at the specified path was deselected.

 

func collectionView(UICollectionView, shouldBeginMultipleSelectionInteractionAt: IndexPath) -> Bool

                                                                                                                      --方法:断定是否允许客户双手指平移操作

--Asks the delegate whether the user can select multiple items using a two-finger pan gesture in a collection view.

 

func collectionView(UICollectionView, didBeginMultipleSelectionInteractionAt: IndexPath)

                                                                                                                      --方法:(客户互动)双手指开始选中多项时,自动调用该方法

--Tells the delegate when the user starts using a two-finger pan gesture to select multiple items in a collection view.

 

func collectionViewDidEndMultipleSelectionInteraction(UICollectionView)

                                                                                                                      --方法:(客户互动)双手指抬起时,自动调用该方法

--Tells the delegate when the user stops using a two-finger pan gesture to select multiple items in a collection view.

 

Managing Cell Highlighting -- 管理cell的高亮状态

 

func collectionView(UICollectionView, shouldHighlightItemAt: IndexPath) -> Bool

                                                                                     --方法:(客户互动)断定是否高亮被点击的item,可以在这里处理被点击的item

--Asks the delegate if the item should be highlighted during tracking.

 

func collectionView(UICollectionView, didHighlightItemAt: IndexPath)

                                                                                                                   --方法:在这里配置已经被高亮的item

--Tells the delegate that the item at the specified index path was highlighted.

 

func collectionView(UICollectionView, didUnhighlightItemAt: IndexPath)

                                                                                                                   --方法:在这里配置高亮刚结束后的item

--Tells the delegate that the highlight was removed from the item at the specified index path.

 

Tracking the Addition and Removal of Views -- 跟踪view的增加与移除

 

func collectionView(UICollectionView, willDisplay: UICollectionViewCell, forItemAt: IndexPath)

                                                                                                                   --方法:在cell添加进content之前,自动调用该方法

--Tells the delegate that the specified cell is about to be displayed in the collection view.

 

func collectionView(UICollectionView, willDisplaySupplementaryView: UICollectionReusableView, forElementKind: String, at: IndexPath)

                                                                                                                   --方法:在额外视图添加进centent之前,自动调用该方法

--Tells the delegate that the specified supplementary view is about to be displayed in the collection view.

 

func collectionView(UICollectionView, didEndDisplaying: UICollectionViewCell, forItemAt: IndexPath)

                                                                                                      --方法:在移除某cell时,自动调用该方法

--Tells the delegate that the specified cell was removed from the collection view.

 

func collectionView(UICollectionView, didEndDisplayingSupplementaryView: UICollectionReusableView, forElementOfKind: String, at: IndexPath)

                                                                                                          --方法:在移除某额外视图时,自动调用该方法

--Tells the delegate that the specified supplementary view was removed from the collection view.

 

Handling Layout Changes                      --处理布局的变化

 

func collectionView(UICollectionView, transitionLayoutForOldLayout: UICollectionViewLayout, newLayout: UICollectionViewLayout) -> UICollectionViewTransitionLayout

                                                                                       --方法:在这里配置过渡的新的layout对象

--Asks for the custom transition layout to use when moving between the specified layouts.

 

func collectionView(UICollectionView, targetContentOffsetForProposedContentOffset: CGPoint) -> CGPoint

                                                                                       --方法:在这里设置“layout更新后”或者“动画后”的content offset

--Gives the delegate an opportunity to customize the content offset for layout changes and animated updates.

 

func collectionView(UICollectionView, targetIndexPathForMoveFromItemAt: IndexPath, toProposedIndexPath: IndexPath) -> IndexPath

                                                                                       --方法:(客户交互)正在移动item的时候,自动调用该方法

--Asks the delegate for the index path to use when moving an item.

 

Managing Actions for Cells -- 管理cell的动作,基本上已经丢弃

 

func collectionView(UICollectionView, shouldShowMenuForItemAt: IndexPath) -> Bool

                                                                                                            --方法:断定长按item时,是否显示可编辑菜单

--Asks the delegate if an action menu should be displayed for the specified item.

--Deprecated

 

func collectionView(UICollectionView, canPerformAction: Selector, forItemAt: IndexPath, withSender: Any?) -> Bool

                                                                                                   --方法:断定是否允许编辑菜单的命令功能,例如复制粘贴命令

--Asks the delegate if it can perform the specified action on an item in the collection view.

--Deprecated

 

func collectionView(UICollectionView, performAction: Selector, forItemAt: IndexPath, withSender: Any?)

                                                                                    --方法:(客户交互)点击编辑菜单的某命令时,自动调用该方法

--Tells the delegate to perform the specified action on an item in the collection view.

Deprecated

 

Managing Focus in a Collection View -- 管理collection view 的焦点

func collectionView(UICollectionView, canFocusItemAt: IndexPath) -> Bool

                                                                                           --方法:在这个方法里,断定某item是否可获取焦点

--Asks the delegate whether the item at the specified index path can be focused.

 

func indexPathForPreferredFocusedView(in: UICollectionView) -> IndexPath?

                                                                                              --方法:返回可优先获取焦点的cell

--Asks the delegate for the index path of the cell that should be focused.

 

func collectionView(UICollectionView, shouldUpdateFocusIn: UICollectionViewFocusUpdateContext) -> Bool                                                                                         --方法:断定焦点的改变能否发生

--Asks the delegate whether a change in focus should occur.

 

func collectionView(UICollectionView, didUpdateFocusIn: UICollectionViewFocusUpdateContext, with: UIFocusAnimationCoordinator)                                     --方法:焦点改变时,自动调用该方法

Tells the delegate that a focus update occurred.

 

Controlling the Spring-Loading Behavior -- 控制弹簧加载行为,我也不懂

 

func collectionView(UICollectionView, shouldSpringLoadItemAt: IndexPath, with: UISpringLoadedInteractionContext) -> Bool

                                                                                                    --方法: 断定某cell是否允许弹簧加载行为

--Returns a Boolean value indicating whether you want the spring-loading interaction effect displayed for the specified item.

 

Instance Methods -- 实例方法

应该就是管理cell动作的方法的更新版了

func collectionView(UICollectionView, contextMenuConfigurationForItemAt: IndexPath, point: CGPoint) -> UIContextMenuConfiguration?

 

func collectionView(UICollectionView, previewForDismissingContextMenuWithConfiguration: UIContextMenuConfiguration) -> UITargetedPreview?

 

func collectionView(UICollectionView, previewForHighlightingContextMenuWithConfiguration: UIContextMenuConfiguration) -> UITargetedPreview?

 

func collectionView(UICollectionView, willPerformPreviewActionForMenuWith: UIContextMenuConfiguration, animator: UIContextMenuInteractionCommitAnimating)


 

 

 

 

你可能感兴趣的:(IOS,API阅读,Collection,Views相关)