Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch screen storyboard constraints in iOS Universal app

I'm working on a LaunchScreen.storyboard file for an iOS Universal app in Xcode 7.3.

I must use only constraints defined in storyboard, because the launch screen will be shown before the app will be loaded (can't configure constraints programmatically in a UIViewController subclass).

The background image in the main UIViewController has

  • aspect-ratio (3456:2592),
  • center vertically and
  • center horizontally constraints.

I'm trying to obtain the following conditions:

  • maintain the background image aspect-ratio,
  • activate backgroundImageView.Top = containerView.Top when screen width <= screen height enter image description here
  • activate backgroundImageView.Leading = containerView.Leading - 20 when screen width > screen height enter image description here

The problem is that storyboard constraint definition by size classes is not powerful enough to express conditions like screen width >/<= screen height (e.g.: an iPad Air Fullscreen has always regular width and height, but screen width < screen height in portrait mode and screen width > screen height in landscape mode).

I tried also to define the background image asset set by device, but it allows only to specify iPhone/iPad x1, x2 and x3 versions of the image.

like image 498
horothesun Avatar asked May 25 '16 09:05

horothesun


Video Answer


1 Answers

You don't need auto-layout for this. Make the UIImageView fill the whole screen, then select the Aspect Fill mode for the background UIImageView.

Select "Aspect Fill" mode

Result:

enter image description here

Note that the background image (1) keeps the aspect ratio, (2) centered horizontally and vertically, and (3) automatically scale up to fit the longest axis.

like image 140
kennytm Avatar answered Oct 12 '22 16:10

kennytm