I'm trying to replace the default iOS device rotation animation on my UIcollectionView. I'm using viewWillTransitionToSize and the targetTransform() on the transitionCoordinator to prevent the default view rotation, and then use a transform to rotate each visibleCell into the correct orientation. It works fine, except:
- The Cells on the immediate outer bounds of the visible rect are not getting rotated.
- My logs show that the collectionView.visibleCells() array is giving me what it is supposed to: the visible cells, but I found that if i let the view rotate with the default animation, the visibleCells array gives me the visible Cells PLUS the cells in the immediate neighbourhood.
- I've been trying to access these "neighbourhood" cells so I can rotate them but all my attempts failed with a bang.
Here’s my implementation of 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
}
})}
})
)
Here a quick gif. to ilustrate the problem: http://www.blessinglopes.com/Info
Any Help will be greatly appreciated! Thank you!
I have solved the problem by implementing a separate thread in which the cell is animated. You can check out the code in the git repository below.
https://github.com/rakeshbs/RotatingCollectionView