iosautolayoutsize-classes

Autolayout + size classes: Possible to distinguish between different iPhone X and other devices?


While autolayout and size classes are a great way to define different constraints and thus different layout for different devices like iPhone and iPad it seems that it is not possible to automatically distinguish between devices with (iPhone X, Xs, etc) and without (iPhone 8, 8 Plus, 7, etc.) safe areas.

Is this correct?

One of my ViewControllers uses a ScrollView as root view. The content shows some information and below a button which is positions near the bottom of the screen to be easily accessible.

While this works great on iPhone X like devices, the button is not visible without scrolling on older devices without safe areas.

I would like to use size classes to automatically distinguish between the two device types to position the button in different ways. However, all iPhone devices have compact width and regular height. So, is there no way to use size classes to layout for different iPhone devices. Do have to do this programmatically?


Solution

  • You are correct, at the moment there's no way to distinguish devices with top and bottom padding from the others using only Size Classes.

    This because the "Safe Area" is present also in other iPhones (iPhone 8, 8 Plus, 7), but it's equal to the leading and trailing margins of the view controllers (safeAreaInsets = 0).

    Apple is trying to make our layouts indipendents from the safeAreaInsets value.

    I agree with you that this would be a really helpful implementation.