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?
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.
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.
In my case it happens for all labels / buttons with custom fonts and intrinsic (not explicitly defined) sizes. Looks like an Xcode bug.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With