Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Misplaced views each time Xcode restarts

I'm using storyboards for the first time in my app

When I close Xcode, I have 0 warnings about misplaced views or anything pertaining to my storyboard. When I restart Xcode and open the storyboard, 3 out of my 15 scenes have misplaced view warnings.

Without touching anything (other than selecting the file), I can issue a git status and see that the .storyboard file has changes. If I git diff, I see this included in multiple areas of the file:

<variation key="widthClass=compact" misplaced="YES">
    <rect key="frame" x="8" y="56" width="130" height="34"/>
</variation>

If an element already had <variation key="widthClass=Compact" node, then the misplaced attribute and rect node are added.

The only thing I have to do to get the warnings to go away is click on each one, make sure "Update Frame" is selected, and click "Fix Misplacement". That fixes everything until I restart Xcode.

The basic structure of my scene is:

UIView
    UICollectionView
        UICollectionReusableView
        UICollectionViewCell
        UICollectionViewCell
    UISegmentedControl

How can I prevent this from happening each time I restart?

like image 223
djibouti33 Avatar asked Mar 26 '15 22:03

djibouti33


3 Answers

This generally happens when you have not set the constraints properly.

Try removing all views inside the UIViewController and adding newly again along with your constraints.

Clean and run your code.

like image 62
Sushree Swagatika Avatar answered Oct 22 '22 19:10

Sushree Swagatika


One possible reason for misplaced views is: If you have used live views(IBDesignables) in storyboards then if you open the storyboard and quickly move to some other file before the IB has finished building all the live views then the the views get misplaced. The IB starts building the live views as soon as you view the story board in the editor. To fix the misplaced views, allow IB some time to finish building the storyboard by staying on the storyboard for few moments, and the misplaced views will get fixed.

like image 2
SHN Avatar answered Oct 22 '22 19:10

SHN


In my case it happens for all labels / buttons with custom fonts and intrinsic (not explicitly defined) sizes. Looks like an Xcode bug.

like image 2
SoftDesigner Avatar answered Oct 22 '22 19:10

SoftDesigner