I have a pager whole screen collectionview. When device rotation, first cell of collectionview is fitting to collectionview on landscape and portrait mode. But when I scroll next cell on collectionview, it is showing two cell. And it is not fitting all screen. How can I fit all cells size to collectionview although I scroll collectionview and rotate. I tried invalideLayout() and many way. But I couldn't achive. Just I only want, collectionviewcell fitted to whole screen in any situation although scroll and rotate.
P.S collectionviewcell size should be whole screen size.
public override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) {
if UIDevice.current.orientation.isLandscape,
let layout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout {
let width = view.frame.height
layout.itemSize = CGSize(width: width, height: UIScreen.main.bounds.width)
layout.invalidateLayout()
} else if UIDevice.current.orientation.isPortrait,
let layout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout {
let width = view.frame.width
layout.itemSize = CGSize(width: width , height: UIScreen.main.bounds.height)
layout.invalidateLayout()
}
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let width = view.frame.size.width
return CGSize(width: width , height: UIScreen.main.bounds.height)
}

sizeForItemAtIndexPath? - iPeter