I like to build apps that support also landscape mode. I have an iPhone 7 Plus and I use landscape mode quite often.

I’m using a lot of UICollectionViews and UITableViews in my apps and there’s a method that recognizes when a user changes the orientation of the device.

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
    if let layout = self.collectionViewLayout as? UICollectionViewFlowLayout {


This method notifies the container that the size of its view is about to change. In order to draw the UI correctly I need to react to this change. I do it by invalidating the current layout. It will then automatically trigger the drawing of a new layout.

Leave a Comment

Your email address will not be published.