jjramos
jjramos

Reputation: 2094

Design using size classes not working as expected

I want to describe an issue (and its corresponding solution) I was having with Size Classes.

For a UIViewController and iPhone-only environment, I want to have a different layout for landscape and portrait. I have the corresponding designs on Interface Builder using Size Classes. However, when running the application on the simulator, I always get the portrait layout regardless of the device orientation.

I have tried 2 different approaches:

  1. Creating the portrait layout for the Any-Any Size Class and the landscape one for wAny-hCompact.
  2. Creating the portrait layout for the wCompact-hRegular, the landscape one for wAny-hCompact and a different one for Any-Any.

In both cases, everything looks good in the Preview feature of Interface Builder for all iPhone devices and orientations but on the simulator I always see the portrait layout regardless of device orientation.

I am using Xcode 7.2 and I have tried all iPhone Simulators on both iOS 8.4 and 9.2. No warnings about autolayout constraints are seen on any of the Size Classes.

Upvotes: 0

Views: 469

Answers (1)

jjramos
jjramos

Reputation: 2094

The problem turned out to be unrelated to the usage of Size Classes. I didn’t notice I was getting this warning when presenting the problematic view controller: Presenting view controllers on detached view controllers is discouraged

Fixing that issue and removing that warning made everything work as expected.

Upvotes: 0

Related Questions