Search code examples
iosiphoneautolayoutxcode7size-classes

Size classes not working properly in Swift 2.0


I am working on a Universal application with all orientation support. I followed below steps

  1. Selecting width compact & height any size class, see below:

enter image description here

As I can understand above image describes that if we want to design layout for iPhone-4 to iPhone-6 than we should use width compact & height any size class.

While using width compact & height any class I put constraints like in the below image enter image description here

  1. Selecting width compact & height regular size class, see below:

enter image description here

This is bit confusing for me so what I did is to consider width compact & height regular size class for iPhone-6 Plus only.

While using width compact & height regular size class I put constraints same as I put for width compact & height any size class but changed the values of constraints, see in the below image

enter image description here

In above image have a look at red box in right side where I have added multiple values for both height and width constraint for three size classes width compact & height any, width compact & height regular, width regular & height regular.

My issue with size classes: When I am running application on simulator or on device from iPhone-4 to iPhone-6 it is showing the UIImageView with height and width I assigned to width compact & height regular i.e. 250, where it must show UIImageView with height and width I assigned to width compact & height any i.e. 200.

While running app on iPhone-6 Plus or on iPad it is showing correct height and width which I assigned for them.

Query: How I can achieve controller objects like UIImageView etc. in different sizes of different iPhones?


Solution

  • All iPhone models in portrait have the same trait RH-CW. What you are trying to achieve will not work, because the the any will be converted into regular, thus regular will take precedence over any.

    In portrait, iPhone 6 Plus uses the compact horizontal and regular vertical size classes.

    In portrait, iPhone 6, iPhone 5, and iPhone 4s use the compact horizontal and regular vertical size classes.