Any-Any size class ignored for ios7

2019-04-06 16:59发布

问题:

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:

回答1:

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.