skip to Main Content

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

2

Answers


  1. adjusting the center.y of the image view relative to 0.4 of the launch screen height

    You cannot set a center anchor in relation to a height. There is no such relationship.

    Use an invisible spacer view with its top pinned to the top of the superview. The spacer view height can be set relative to the superview height, and now the image view vertical center can be set relative to the spacer view bottom.

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search