我正在尝试替换UIcollectionView上的默认iOS设备旋转动画。
我在transitionCoordinator上使用viewWillTransitionToSize和targetTransform()来防止默认视图旋转,然后使用转换将每个visibleCell旋转到正确的方向。
它工作正常,除了:
可见矩形直接外边界上的像元不会旋转。
我的日志显示collectionView.visibleCells()数组正在为我提供应有的功能:可见单元格,但是我发现,如果让视图以默认动画旋转,visibleCells数组将为我提供可见单元格加上单元格在附近地区。
我一直在尝试访问这些“邻居”单元格,以便我可以旋转它们,但是所有尝试都失败了。
这是我对ViewWillTransitionTosize的实现:
override func viewWillTransitionToSize( size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator){
super.viewWillTransitionToSize(size , withTransitionCoordinator: coordinator)
let transf : CGAffineTransform = coordinator.targetTransform()
let invertedRotation = CGAffineTransformInvert(transf)
let currentBounds = view.bounds
coordinator.animateAlongsideTransition({
_ in
self.view.transform = CGAffineTransformConcat(self.view.transform, invertedRotation )
self.undoRotation = CGAffineTransformConcat(self.undoRotation, transf)
self.view.bounds = currentBounds
}, completion: ({ finished in
if ( finished != nil){
UIView.animateWithDuration(0.5, animations: {
for cell in self.collectionView!.visibleCells(){
cell.contentView.transform = self.undoRotation
}
})}
})
)
这里是一个快速的gif。解决问题:http://www.blessinglopes.com/Info
任何帮助将不胜感激!
谢谢!
最佳答案
我已经通过实现一个单独的线程来解决该问题,在该线程中该单元具有动画效果。您可以在下面的git存储库中签出代码。
https://github.com/rakeshbs/RotatingCollectionView