Search code examples
swiftxcodeautolayoutstoryboardlaunch-screen

How to configure UIImageView on the launch screen view with relative value through storyboard?


Today I have a task with adjusting the center.y of the image view relative to 0.4 of the launch screen height. As you know, it cannot be customized with view controllers because the launch screen is independent. This is why I am setting up the image view through the storyboard. On different screens, the image is displayed at different heights, since the rigidly anchored top constraint sets a specific value (270, for example). In my case, it is necessary that the launch screen itself counts 0.4 from the height of its view and set this value for the center of the image view. How can I do this with storyboards?

Top Anchor constraint

iPhone 12 displaying

iPhone 8 displaying

iPhone SE2 displaying


Solution

  • First, add a center Y constraint like this:

    enter image description here

    The constraint's second item would be Superview.Center Y. Change that to Superview.Bottom instead:

    enter image description here

    Because the superview in this case is the root view, its bottom will be equal to its height. Now you can change the multiplier to 0.4 to achieve the desired effect.