Currently experiencing some issues with the Flow layout using a collection view on iPads. I am currently developing an app that displays posts in a flow-layout, making it look nice and sleek. However, when testing the app on all of the devices, I noticed that the display changes on:
- iPad 5th Generation
- iPad Air
- iPad Air 2
- iPad Pro (9,7 inch)
But the remaining iPads, it displays properly. What seems to be the problem here? I am currently using this code to style my layout inside the CollectionView:
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
switch UIDevice().screenType {
case .iPhoneX:
return CGSize(width: 180.0, height: 180.0)
break
case .iPhone5:
return CGSize(width: 152.0, height: 152.0)
break
case .iPhone6:
return CGSize(width: 180.0, height: 180.0)
break
case .iPhone6Plus:
return CGSize(width: 200.0, height: 200.0)
break
case .iPad:
return CGSize(width: 400.0, height: 400.0)
break
case .iPadTwo:
return CGSize(width: 400.0, height: 400.0)
break
case .iPadThree:
return CGSize(width: 400.0, height: 400.0)
break
default:
return CGSize(width: 200.0, height: 200.0)
break
}
}
'iPad Two' and 'iPad Three' is just some enums I tried to create, in an attempt to determine iPad type and if I got an output printing some text (but it just falls down to default), regardless of the iPad.
And this is my screen sizes:
switch UIScreen.main.nativeBounds.height {
case 960:
return .iPhone4
case 1136:
return .iPhone5
case 1334:
return .iPhone6
case 2208:
return .iPhone6Plus
case 1024:
return .iPad
case 1366:
return .iPadTwo
case 834:
return .iPadThree
case 2436:
return .iPhoneX
break
default:
return .unknown
}
And here is a visual representation of my problem, occuring on the listed devices, but not on the rest:
How it's supposed to look like:
What it looks like on the listed devices:
I would really appreciate the help if someone could help me to troubleshoot this, as I can't seem to find a properly working solution.