0

I have an UICollectionViewController and I try to put two cells each line with Autolayout to support rotation.

// portrait
+-------------+
|+----+ +----+|
||cell| |cell||
|+----+ +----+|
+-------------+

// Landspace
+-------------------+
|+-------+ +-------+|
||cell   | |cell   ||
|+-------+ +-------+|
+-------------------+

So I use some NSLayoutConstraint for the cells. and willRotateToInterfaceOrientation&viewWillTransitionToSize for rotation:

// MARK: - Rotation
// iOS7
override func willRotateToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval) {
    self.collectionView!.collectionViewLayout.invalidateLayout()
}

// iOS8
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
    self.collectionView!.collectionViewLayout.invalidateLayout()
}

Things goes well until I pushed another ViewController, I found if I rotation in new ViewController and goes back(with default NavigationBar), the UICollectionViewController cannot exec either willRotateToInterfaceOrientation and viewWillTransitionToSize.

So how can I fit the right size when I go back through NavigationBar?

Sirui Zhuang
  • 665
  • 5
  • 12

0 Answers0