Ios 如何在旋转期间删除UICollectionView的淡入淡出动画?

Ios 如何在旋转期间删除UICollectionView的淡入淡出动画?,ios,animation,uicollectionview,rotation,uicollectionviewlayout,Ios,Animation,Uicollectionview,Rotation,Uicollectionviewlayout,我只是尝试在旋转期间调整CollectionView的动画,这样就不会有任何像这样的淡入淡出效果 只需移动视图即可。 所以在一次小小的搜索之后,我发现我仅仅通过 重写UICollectionViewFlowLayout的两个方法 override func initialLayoutAttributesForAppearingItem(at itemIndexPath: IndexPath) -> UICollectionViewLayoutAttributes? { return n

我只是尝试在旋转期间调整CollectionView的动画,这样就不会有任何像这样的淡入淡出效果

只需移动视图即可。 所以在一次小小的搜索之后,我发现我仅仅通过 重写UICollectionViewFlowLayout的两个方法

 override func initialLayoutAttributesForAppearingItem(at itemIndexPath: IndexPath) -> UICollectionViewLayoutAttributes? {

return nil

}
 override func finalLayoutAttributesForDisappearingItem(at itemIndexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
      return layoutAttributesForItem(at: itemIndexPath) 

}
但另一个问题开始生效:当我在两条消息之间接收消息时,就像延迟接收消息一样 蓝色消息不仅向下移动,而且蓝色消息的旧实例在短时间内保持不变,然后向下移动。但如果我回到最初的偏好,两者都是

  override func initialLayoutAttributesForAppearingItem(at itemIndexPath: IndexPath) -> UICollectionViewLayoutAttributes? {

return nil

}
 override func finalLayoutAttributesForDisappearingItem(at itemIndexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
      return nil 

}
消息以整洁的方式适当地移动,但在旋转过程中会再次出现淡入淡出的效果


这件事是非常困惑我,请也许有人有任何线索,我如何保持旋转动画没有褪色的效果,使信息动画效果像一个普通的信息运动

我想我找到了解决办法。 1) 我需要找出正在CollectionView中插入的元素的索引路径。 2) 计算插入IndexPath后放置的下一个元素(当我在两条消息之间接收消息时,如延迟接收消息) 3) 将新的initialLayoutAttributesForAppearingItem和FinallYoutAttributesforIsAppearinGitem应用到上面派生的IndexPaths数组中,对于其余元素,我们仅应用该首选项

 override func initialLayoutAttributesForAppearingItem(at itemIndexPath: IndexPath) -> UICollectionViewLayoutAttributes? {

return nil

}
    override func finalLayoutAttributesForDisappearingItem(at itemIndexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
  return layoutAttributesForItem(at: itemIndexPath) 

 }
这是代码

   override func prepare(forCollectionViewUpdates updateItems: [UICollectionViewUpdateItem]) {

    super.prepare(forCollectionViewUpdates: updateItems)
               insertingIndexPaths.removeAll()
    print("begining : \(insertingIndexPaths)")


    // create an array

    let fullAmountOfCells = collectionView?.numberOfItems(inSection: 0)
    print("number of items: \(fullAmountOfCells)")

    for update in updateItems {
        if let indexPath = update.indexPathAfterUpdate,
            update.updateAction == .insert {
            insertingIndexPaths.append(indexPath)
            print("Example if indexPath if for loop:\(indexPath)")
        }

   }
    let lastPathOfInsertingElement = insertingIndexPaths.last
    let differenceBetweenFullAmountAndLastInsertElement = fullAmountOfCells! - (lastPathOfInsertingElement?.item)! - 1

    if differenceBetweenFullAmountAndLastInsertElement > 0 {
        for numeric in 1...differenceBetweenFullAmountAndLastInsertElement {
            insertingIndexPaths.append(IndexPath(item: numeric + (lastPathOfInsertingElement?.item)!, section: 0))
        }
        print("True array to be modified with attributes:\(insertingIndexPaths)")

}
 }

override func finalizeCollectionViewUpdates() {
    super.finalizeCollectionViewUpdates()
  //  ChatLogController.orientation = UIDevice.current.orientation
//    print(  ChatLogController.orientation = UIDevice.current.orientation)
    insertingIndexPaths.removeAll()
    movingIndexPath.removeAll()
}



   override func initialLayoutAttributesForAppearingItem(at itemIndexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
    let attributes = super.initialLayoutAttributesForAppearingItem(at: itemIndexPath)

    if insertingIndexPaths.contains(itemIndexPath) {
        // attributes?.alpha = 0.0
        //attributes?.transform = CGAffineTransform(scaleX: 0.1, y: 0.1)

        print("Process in initialLayoutAttributesForAppearingItem: \(itemIndexPath)")
           return attributes

    } else {
         print("Process in initialLayout set to nil: \(itemIndexPath)")
        return nil
    }


}








  override func finalLayoutAttributesForDisappearingItem(at itemIndexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
let attributes = super.initialLayoutAttributesForAppearingItem(at: itemIndexPath)

if insertingIndexPaths.contains(itemIndexPath) {
    // attributes?.alpha = 0.0
    //attributes?.transform = CGAffineTransform(scaleX: 0.1, y: 0.1)


    return nil

} else {
    print("processing final layout and it to leyoutAttributeForItem(at: \(itemIndexPath)")
    return layoutAttributesForItem(at:itemIndexPath)
}



  }