We have a number of iOS apps that several different developers contribute to. A problem that I continue to notice is that views in our storyboards will shift out of the position they were put in or resize so that they are smaller, which on labels that were sized to fit text originally becomes painfully obvious when the labels all of a sudden are truncating their text.
I'm noticing these degradations of our views appear in commits to our Git repository when the developer did not directly make any edits to the storyboard. They may have viewed the storyboard in Interface Builder, but did not make any real changes to the storyboard. The changes were nevertheless saved and committed along with what they were working on.
When I do a text compare between the storyboard files before and after the responsible commits I see small changes to view frames such as:
<rect key="frame" x="203" y="8" width="362" height="29"/>
|
V
<rect key="frame" x="203" y="7.5" width="362" height="29"/>
and
<rect key="frame" x="446.00000170260091" y="7" width="302" height="30"/>
|
V
<rect key="frame" x="446" y="7" width="302" height="30"/>
and
<rect key="frame" x="364" y="3" width="200" height="38"/>
|
V
<rect key="frame" x="363" y="3" width="200" height="38"/>
and
<rect key="frame" x="284" y="7" width="97" height="30"/>
| |
V V
<rect key="frame" x="283" y="7" width="96" height="30"/>
and
<rect key="frame" x="384.00001078580522" y="7" width="101" height="30"/>
| |
V V
<rect key="frame" x="383.00000530853856" y="7" width="100" height="30"/>
Most of the time the numbers for frame dimensions are changing by just a small amount, either an integer value changes by one or a floating point value is truncated or the decimal portion is changed minorly.
Other times, the values are changing by a few points though like:
<rect key="frame" x="334" y="3" width="200" height="38"/>
|
V
<rect key="frame" x="331" y="3" width="200" height="38"/>
and
<rect key="frame" x="251" y="7" width="223" height="30"/>
|
V
<rect key="frame" x="251" y="7" width="220" height="30"/>
and
<rect key="frame" x="478" y="3" width="274" height="38"/>
| |
V V
<rect key="frame" x="475" y="3" width="276" height="38"/>
Note that all of these example frame changes were taken from the same example commit when the developer did not intend to make a single change to the storyboard. There were 269 differences in the XML between the two versions of the file, all of them being these slight changes in frame sizes or positions. The storyboard XML is ~9000 lines.
It seems the issue may have something to do with IB's use of floating point numbers and rounding errors and the differences that become off by a few pixels could be an aggregation of these rounding errors over a period of several times opening, parsing and re-serializing the data.
This is just a theory though as I've not been able to pinpoint the exact cause of the unwanted changes. Often commits don't make any significant changes to the frames at all, only insignificant floating point changes such as 446.00000055262581 -> 446.00000112002783. But when the serious changes occur, they seem to occur in large numbers.
The commits between which the changes occur are also made by the same developer using the same version of Xcode and Interface Builder too. In this example commit where this data was taken, the document tag is <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6250" systemVersion="14A389" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none" initialViewController="JAD-vj-VfC">
in both versions of the storyboard file for example.
Other than being sure to check not to commit insignificant or unintended changes to storyboard files, I'd like to narrow down what is causing these unwanted changes to our storyboard views. If it's something we can avoid doing that is causing the issue, we can be aware of the cause.
Update: As Tim helpfully noted, this issue does seem to be caused while using Interface Builder on a retina display. All the developers that have caused the problem have retina MacBook Pros. Those of us without retina displays have not experienced the issue.