Size Classes in iOS 7

2020-02-10 07:33发布

问题:

I created a new app in Xcode 6 using Size Classes. After testing with iOS 7, I can't figure out how to get iPhone to display a certain size class while in landscape mode.

I first developed the UI with iPhone landscape as wAny hCompact, but iOS 7 doesn't recognize that. I had iPhone portrait in wAny hAny.

I then changed it so now I'm using wCompact hRegular for iPhone portrait. I then modified wAny hAny to be the landscape layout. But it's not using that layout when the iOS 7 device is in landscape.

Is iOS 7 able to use different size classes based on the device being portrait or landscape? If so, which size class should I be using?

Reference: Really helpful information about backwards compatibility with size classes.

ps. I'm not concerned with iPad because the device does not display a different size class based on the device rotation in iOS 8.

回答1:

Size classes works in iOS 7 for sure. But only if you follow several rules:

  • The app is built using Xcode version 6 or later
  • The deployment target of the app is earlier than iOS 8
  • Size classes are specified in a storyboard or xib file
  • The value of the height component is not compact (yep, this is your case, it's not possible in iOS 7, unfortunatelly)

There is a little explanation here: https://stackoverflow.com/a/24976792/2190175



回答2:

No I'm afraid that Size Classes were introduced in iOS 8. You could write some conditional code to run on iOS to determine the screen/view size/orientation and change the the layout that way when iOS 8 becomes your minimum target the conditional code can be removed.