Skip to content

Instantly share code, notes, and snippets.

@puls
Created November 6, 2014 01:53
Show Gist options
  • Select an option

  • Save puls/203336da4ef59ee204f3 to your computer and use it in GitHub Desktop.

Select an option

Save puls/203336da4ef59ee204f3 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6250" systemVersion="14A389" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6244"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="ztc-eJ-ujb">
<objects>
<viewController id="mhR-QO-pIv" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="miT-Je-PDN"/>
<viewControllerLayoutGuide type="bottom" id="twd-Iu-phu"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="S5t-92-IaS">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Tiw-GD-Zb0">
<rect key="frame" x="279" y="290" width="42" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="hG4-ug-beR">
<rect key="frame" x="279" y="227" width="42" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="centerX" secondItem="Tiw-GD-Zb0" secondAttribute="centerX" id="22E-n9-cHn"/>
<constraint firstAttribute="centerY" secondItem="Tiw-GD-Zb0" secondAttribute="centerY" id="e0l-lU-8iG"/>
<constraint firstAttribute="centerX" secondItem="hG4-ug-beR" secondAttribute="centerX" id="hyd-U7-34x"/>
<constraint firstItem="Tiw-GD-Zb0" firstAttribute="top" secondItem="hG4-ug-beR" secondAttribute="bottom" constant="42.5" id="iUf-7F-iNI"/>
</constraints>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="qXy-ix-3p9" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="228" y="284"/>
</scene>
</scenes>
</document>
@puls
Copy link
Author

puls commented Nov 6, 2014

Here's a very simple iOS storyboard with a single view controller, its view, and two labels that are horizontally centered. It should be fairly clear that this is safe to open in Xcode to play along.

Notice that line 37 specifies a spacing constraint with a constant of 42.5 pt. This should be okay, since coordinates on iOS are specified in floating point, and most iOS devices today can display half-point coordinates on full pixels.

Even if it's not okay—I'll even take "not a good idea"—there are a number of failure modes I'd accept, none of which are what actually happens.

Open this file on a 2x display (like a Retina MacBook Pro or, if you want to make me really jealous, a Retina 5K iMac) and you'll see everything is great. Open it on a 1x display and you'll see you have auto layout issues.

You can easily fix those auto layout issues by updating frames, but then if you move back to a 2x display, you'll have auto layout issues once again.

You can even see this in real time if you have one of each display and drag the Xcode window back and forth.

Steps to Reproduce:

  1. Open the attached storyboard on a 1x display. See auto layout issues.
  2. Move it to a 2x display. No auto layout issues.
  3. Fix the issues by updating frames on a 1x display.
  4. Move it to a 2x display. Now there are auto layout issues.

Expected Results:
Any of the following:

  • Consistent rounding behavior
  • Disallowing fractional constraint constants
  • Having Xcode do calculations that don't depend on the screen resolution

Actual Results:
Endless streams of hilarity involving unfixable layout constraints.

Version:
Xcode 6.1(6A1052d)
OS X Yosemite 10.10 (14A389)

(Yes, I filed this as rdar://18889965)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment