Search code examples
iosuiviewautolayout

How to deal with Misplaced View warning in Xcode storyboards?


I am trying to change the position of a UIScrollView that is inside a UIView, but whenever I change its position I get a warning which says that "Frame for scroll view will be different at run time" (see image below). How do I handle this properly?

enter image description here

UIScrollView Constraints:

enter image description here

UIView inside UIScrollView constraints:

enter image description here

Here I am trying to move the UIScrollView inside the root UIView.

enter image description here


Solution

  • That warning simply means that where you have the view positioned in canvas (aka where you have dragged the view to in Xcode's ui editor), does not match the location where the view will be positioned when the app is running, based on the constraints you've set.

    First check that your constraints are correct, and that they will cause the view to appear where you want at run time.

    If the constraints are correct, and the view just needs to be repositioned in the storyboard you can click on the view then go to Editor > Resolve Auto Layout Issues > Update Frames. Then Xcode will automatically update the position of the view in canvas based on the existing constraints.