简体   繁体   中英

UICollectionView size: iOS9 vs. iOS8

In my app I want to compute the best cell height so that cells match perfectly into the visible area.

What is the best way to get the size of the visible rect? With this I mean the space between the navigationbar and the bottom of the screen.

Currently I get the size with

self.collectionView!.frame.size

but this contains the area of the statusBar and the navigationBar. So I substract the size of nav- and stautusbar. This works for iOS9, but not on iOS8.

So, how do I get the visible area only for all devices?

Not really an answer, but as a workaround, you could detect the iOS version and apply modifications according to it:

if ( ([[[UIDevice currentDevice] systemVersion] compare:@"9.0" options:NSNumericSearch] != NSOrderedAscending) ) { /* iOS 9.0 or greater */ }

Of course, it would be better to define your layouts using constraints relative to the Top Layout Guide ( ideally using an opaque navigation bar) to avoid messing with that, or add 20 points to your top constraints when detecting certain iOS versions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM