Any-Any size class ignored for ios7
Asked Answered
G

1

8

I'm developing for both iOS7 and 8 iPhone. Since iOS7 doesn't support compact-height size classes, I thought the consensus way to go about this was to use the any-any size class for landscape iPhone layouts, and use portrait compact-width regular-height (cWrH) size class for portrait iPhone layouts.

I set a constraint on a view in any-any, then modify a constraint constant in cWrH to be specific to that size class. However, iOS7 device as well as Xcode preview ignores the any-any constraint, and uses the cWrH constraint for both portrait and landscape orientations.

I have no clue why this is happening. All I want to do is set different constraints depending on orientation.

This is easily replicated using latest Xcode 6.0.1.

Semi-related: How can Xcode 6 adaptive UIs be backwards-compatible with iOS 7 and iOS 6?

Screenshots below:

x and y of rect at 0 in Any-Any y=100 for cWrH size class only

Goa answered 16/10, 2014 at 9:9 Comment(2)
"In iOS 8 and later, you use size classes and Auto Layout to help you meet this expectation by defining how the layout of screens, view controllers, and views should adapt when the display environment changes" developer.apple.com/library/ios/documentation/userexperience/…Haifa
I ran into the same issue and I'm currently using xcode 6.1.1. I think we have to accept that size classes are simply not backward compatible with iOS 7, despite any claims.Allograph
S
0

As per your question what you did is you have given leading,Top,height and width constraints in Any-Any Size Class.

So now its position will be fixed for any devices in landscape and portrait. Now when you changes size class to compact width and make changes in top constraints it will affect both portrait and landscape.

What you need to do using size class with Any-Any to place your controls in View controller and set those constraints which you would like to keep in both portrait and landscape.

e.g.: If you want to keep height and width fixed give those constraints in Any-Any Size Class.

Setting constraints in Any-Any Size Class will keep those constraints similar for both portrait and landscape.

1.) Setting leading and top constraints in portrait you can use width- Compact, height-Regular.

2.) Setting leading and top constraints in landscape you can use width- Any,height-Compact.

Visit link below it has the great explanation and your most of issues related to auto layout using size class will be solved:

http://mathewsanders.com/designing-adaptive-layouts-for-iphone-6-plus/

Hope this solves you problem.

Showpiece answered 24/2, 2015 at 3:25 Comment(1)
The question is specifically about support for iOS7. Sadly, iOS7 completely ignores any size class with height=Compact, so option #2 is not possible for this target.Ferrick

© 2022 - 2024 — McMap. All rights reserved.