17

So each time I open my project in Xcode, I have 100's of warning because the frames of every UI Object has been moved. I have to take the time and go to each UIViewController and update frames on it.

Is there a reason this happens? How can I fix this? Any other information I need to mention?.

Wyetro
  • 8,439
  • 9
  • 46
  • 64
Matthew Krager
  • 225
  • 2
  • 8
  • Having the same problem. It's really annoying. Every time I enter a storyboard file there's a hundred frames that needs updating. Even `.xib` files. – Kelvin Lau Oct 16 '15 at 17:30
  • yes Same problem to restart my XCode. Misplacement View in Story Board , – Kirit Modi Oct 23 '15 at 07:15

6 Answers6

4

Do you use a repository for your code? There may be some configuration file missing, probably not comited properly

Pablo A.
  • 2,042
  • 1
  • 17
  • 27
  • 1
    yes it happens mostly, when we use version control for the code. We should not open a storyboard unless we really want to change it, else the storyboard will be modified right away when we open it, though there wont be much chnages in it. – Teja Nandamuri Aug 28 '15 at 20:35
  • If I am not to use storyboards, then how do people use autolayout and all that? Is everything done programmatically when using git? – Matthew Krager Aug 29 '15 at 23:56
  • Same thing happens with me too, I use SVN for version control and every time I open it, it comes into the modified section, So don't open the story board unless it is necessary. and those warnings are quite a headache.... – Bhaumik Desai Oct 19 '15 at 12:58
  • I'm seeing this issue mainly after Xcode updates (it stores it's version in the storyboard) or poorly developed storyboards shared within teams. As a general rule, if you know you didn't change anything, you can discard the changes (in Project Navigator, right-click on storyboard, then in the shortcut menu select Source Control -> Discard Changes in "Main.Storyboard") – davew Jun 06 '16 at 21:04
4

In my case, this was happening because size-class for which I have set the constraints and layout got changed when I opens the Xcode project. So make sure that the size class remain the same for which you have applied the layout or change it if it has been modified by the Xcode.

If above does not work for you, you can try having a local repository created by the Xcode and commit the code before you quit the Xcode.

Hope this helps!!

Manish Verma
  • 539
  • 1
  • 4
  • 11
1

I believe this was asked previously here: Interface Builder degrades storyboards, resizes and repositions views in small increments

I have not yet seen a fix to the problem, but the answer I posted there likely holds true here. https://stackoverflow.com/a/28577800/682574

At least one source is due to storyboards resolving layouts to either full pixel boundaries (x=7.0, y=10.0) or partial boundaries (x=7.5, y=10.5). As best I can tell, this can be recalculated any time you view the storyboard and the rounding is actually determined based on the current display environment.

You can intentionally cause this behavior by viewing the storyboard on a retina display and then viewing it on a non-retina display. With my dual-monitor display, if I just drag a storyboard from one screen (retina 5k) to another (non-retina) it will generate a flood of misaligned constraints. Unfortunately moving it back doesn't fix them! Try it out for yourself (or don't ... it's a pain to correct).

In a team environment its easy to see how this could happen as soon as two people with different setups view the same storyboard.

How to fix it? I haven't heard of a workflow that properly corrects or avoids the problem unfortunately.

Community
  • 1
  • 1
Tim O'Neil
  • 511
  • 1
  • 7
  • 8
0

Here are a couple of reasons I've seen for intermittently misplaced views. I'm not sure if either of these is responsible for the problem you're seeing -- usually these will cause a few views to be misplaced here and there, not every view in your storyboard. But I've listed them just in case it helps.

  • Different team members may be using different versions of Xcode, which may position certain views slightly differently, and which will certainly change the storyboard file "tool version" and so forth.
  • Constraints are not usually happy with fractional widths/heights in them. This can be difficult to detect -- for example, you may have a view whose intrinsic height is an odd number of pixels vertically centered within a view whose height is an even number of pixels, causing the inner view to start at a half-pixel offset and want to be repositioned lower or higher when the storyboard is re-opened.
Eric Galluzzo
  • 3,191
  • 1
  • 20
  • 20
0

For xib files, you can easily write a script that updates automatically the frames:

ibtool input.xib --update-frames --write input.xib

But, you should not worry about these warnings: the frames will be automatically adjusted during the execution.

Antoine Rosset
  • 1,045
  • 2
  • 13
  • 22
0

Its could happens due to having 4k external display. Everybody in my team does not have this kind of problem, only me.

After opening Xcode tries to align logical points to physical pixels, so everything moves about 0.5 point.

Mike Glukhov
  • 1,758
  • 19
  • 18