zoukankan      html  css  js  c++  java
  • UICollectionView 修改Item时函数执行顺序

      项目中使用Collection时,需要添加一些动画。

      当 Collection 插入或移除 item 时,函数执行的顺序:

    空数据插入Item
      1.[UIApplication sendAction:to:from:forEvent] _IOHIDEvent
      2.类insert函数
      3.[UICollectionView _updateRowsAtIndexPaths:updateAction:]
      4.[UICollectionViewData _prepareToLoadData]
      5.-prepareLayout
      6.-prepareForCollectionViewUpdates:
      7.[UICollectionView _viewAnimationsForCurrentUpdate]
      8.-initialLayoutAttributesForAppearingItemAtIndexPath:
      9.[UICollectionView _updateWithItems:tentativelyForRecording:animator]
      10.-finalizeCollectionViewUpdates

    有数据插入Item
      1. ~ 8.
      9.[UICollectionView _doubleSidedAnimateionsForView:withStartingLayoutAttributes:startingLayout:endingLayoutAttributes:endingLayout:withAnimationSetup:animationCompletion:enableCustomAnimations:customAnimationsType:]
      10.-finalLayoutAttributesForDisappearingItemAtIndexPath:
      11.8/10步骤循环(循环次数取决于剩下的Item个数)
      12.-finalizeCollectionViewUpdates

    空数据移除Item
      1.[UIApplication sendAction:to:from:forEvent:] _IOHIDEvent
      2.类remove函数
      3.[UICollectionView _updateRowsAtIndexPaths:updateAction:]
      4.[UICollectionViewData _prepareToLoadData]
      5.-prepareLayout
      6.-prepareForCollectionViewUpdates:
      7.[UICollectionView _viewAnimationsForCurrentUpdate]
      8.-finalLayoutAttributesForDisappearingItemAtIndexPath:
      9.[UICollectionView _updateWithItems:tentativelyForRecording:animator]
      4.finalizeCollectionViewUpdates

    有数据移除Item
      类似有数据插入Item

    参考博客中对这样的描述:

    In general, layout attributes are linearly interpolated from the initial state to the final state to compute the collection view animations. However, for the newly inserted or removed items, there are no initial and final attributes to interpolate from. To compute the animations for such cells, the collection view will ask its layout object to provide the initial and final attributes through the initialLayoutAttributesForAppearingItemAtIndexPath: and finalLayoutAttributesForDisappearingItemAtIndexPath: methods.
    ....
    During the animation of the bounds change, the collection view acts as if the currently displayed items are removed and inserted again in the new bounds, resulting in a series of finalLayoutAttributesForDisappearingItemAtIndexPath: and initialLayoutAttributesForAppearingItemAtIndexPath: calls for each index path.



    > 参考:[Animating Collection Views](https://www.objc.io/issues/12-animations/collectionview-animations/)
  • 相关阅读:
    一天摄入多少蛋白质比较合理?
    给函数添加元数据(python)
    反转链表(C++实现)
    删除链表的中间节点(C++实现)
    在双向链表中删除倒数第K个链表节点(C++实现)
    在单链表中删除倒数第K个节点(C++实现)
    二叉树的创建及遍历(递归和非递归C++实现)
    删除排序数组中的重复项(C++实现)
    打印两个有序链表的公共部分(C++实现)
    用一个栈实现另一个栈的排序(C++实现)
  • 原文地址:https://www.cnblogs.com/R0SS/p/5714089.html
Copyright © 2011-2022 走看看