How to get cell size of UICollectionView before rotating

I have a UICollectionView that has a width that is a percentage of the parent. When it is rotated I need to know what size it will be, so I can invalidate the layout and redraw the collection view cells as the new full width. I used the viewWillTransitionToSize: withTransitionCoordinator: method, but the size it returns is of the entire screen. Is there an easy way to get a new frame of the UICollectionView before the orientation change takes effect?

+3


source to share


1 answer


    override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
          super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator) 

          print(self.collectionView.frame) // old frame
          coordinator.animateAlongsideTransition({ (UIViewControllerTransitionCoordinatorContext) -> Void in

           }) { (UIViewControllerTransitionCoordinatorContext) -> Void in
              print(self.collectionView.frame) // new frame
           }


    }

      



0


source







All Articles