I am using an UICollectionView
with UICollectionViewFlowLayout
.
I set the size of each cell through the
collectionView:lay
Swift : Collection View Cell that is n% of screen height
I needed was a cell that was a certain percentage of views height, and would resize with device rotation.
With help from above, here is the solution
override func viewDidLoad() {
super.viewDidLoad()
automaticallyAdjustsScrollViewInsets = false
// if inside nav controller set to true
}
override func willRotateToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval) {
collectionViewLayout.invalidateLayout()
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
return CGSize(width: 100, height: collectionView.frame.height * 0.9)
}