Wednesday, February 15, 2017

iOS: Default IB popover transition does strange things

Leave a Comment

I bumped into a strange issue where when a view controller is presented in a popover, the presenting view controllers view is not snapped to the bottom edge of it's superview, in that case the window itself.

AppDelegate code:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {     // Override point for customization after application launch.     let window = UIWindow(frame: UIScreen.main.bounds)     window.rootViewController = UIStoryboard(name: "NavigationController", bundle: Bundle.main).instantiateInitialViewController()     window.makeKeyAndVisible()     window.backgroundColor = .yellow // Needed to detect the issue.     self.window = window      return true } 

Storyboard to test:

<?xml version="1.0" encoding="UTF-8"?> <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16C67" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="4lt-Df-IeL">     <device id="retina5_5" orientation="portrait">         <adaptation id="fullscreen"/>     </device>     <dependencies>         <deployment identifier="iOS"/>         <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>     </dependencies>     <scenes>         <!--Navigation Controller (locked)-->         <scene sceneID="ryr-GW-wBz">             <objects>                 <viewController storyboardIdentifier="NavigationController" definesPresentationContext="YES" id="4lt-Df-IeL" userLabel="Navigation Controller (locked)" sceneMemberID="viewController">                     <layoutGuides>                         <viewControllerLayoutGuide type="top" id="gxR-oc-l6J"/>                         <viewControllerLayoutGuide type="bottom" id="Py7-tH-kHP"/>                     </layoutGuides>                     <view key="view" contentMode="scaleToFill" id="865-DH-bRZ" userLabel="Background View">                         <rect key="frame" x="0.0" y="0.0" width="414" height="736"/>                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>                         <subviews>                             <containerView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="535-Cq-y2B">                                 <rect key="frame" x="54" y="64" width="360" height="618"/>                                 <connections>                                     <segue destination="G7K-pY-ZSi" kind="embed" identifier="ContainerViewController" id="0Mw-mh-5NT"/>                                 </connections>                             </containerView>                             <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="xLz-jb-9OM" userLabel="Left View">                                 <rect key="frame" x="0.0" y="64" width="54" height="672"/>                                 <subviews>                                     <stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="fillEqually" translatesAutoresizingMaskIntoConstraints="NO" id="bls-BC-WIu" userLabel="Left Stack View">                                         <rect key="frame" x="0.0" y="0.0" width="54" height="672"/>                                     </stackView>                                     <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Zbx-7u-5oe" userLabel="Hairline View">                                         <rect key="frame" x="53" y="0.0" width="1" height="672"/>                                         <color key="backgroundColor" red="0.43079092749999998" green="0.1140047376" blue="0.1180379456" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>                                         <constraints>                                             <constraint firstAttribute="width" constant="1" id="kna-vk-GlF" customClass="OnePixelConstraint" customModule="segue_issue" customModuleProvider="target"/>                                         </constraints>                                     </view>                                 </subviews>                                 <color key="backgroundColor" red="0.627" green="0.114" blue="0.14099999999999999" alpha="1" colorSpace="calibratedRGB"/>                                 <constraints>                                     <constraint firstAttribute="width" constant="54" id="2bA-Ap-aup"/>                                     <constraint firstItem="bls-BC-WIu" firstAttribute="leading" secondItem="xLz-jb-9OM" secondAttribute="leading" id="3sM-Bd-eEq"/>                                     <constraint firstAttribute="bottom" secondItem="Zbx-7u-5oe" secondAttribute="bottom" id="9PW-0y-kBv"/>                                     <constraint firstAttribute="trailing" secondItem="Zbx-7u-5oe" secondAttribute="trailing" id="RlN-G4-8iD"/>                                     <constraint firstAttribute="trailing" secondItem="bls-BC-WIu" secondAttribute="trailing" id="anE-HT-oQp"/>                                     <constraint firstItem="Zbx-7u-5oe" firstAttribute="top" secondItem="xLz-jb-9OM" secondAttribute="top" id="bxG-xS-wdV"/>                                     <constraint firstItem="bls-BC-WIu" firstAttribute="top" secondItem="xLz-jb-9OM" secondAttribute="top" id="ds3-z5-Dpv"/>                                     <constraint firstAttribute="bottom" secondItem="bls-BC-WIu" secondAttribute="bottom" id="f9r-FV-enN"/>                                 </constraints>                             </view>                             <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="V3o-XH-Xkn" userLabel="Bottom View">                                 <rect key="frame" x="0.0" y="682" width="414" height="54"/>                                 <subviews>                                     <stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" translatesAutoresizingMaskIntoConstraints="NO" id="fM3-hA-kGa" userLabel="Bottom Stack View">                                         <rect key="frame" x="0.0" y="0.0" width="414" height="54"/>                                     </stackView>                                     <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Gtr-bO-frP" userLabel="Hairline View">                                         <rect key="frame" x="0.0" y="0.0" width="414" height="1"/>                                         <color key="backgroundColor" red="0.43079092749999998" green="0.1140047376" blue="0.1180379456" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>                                         <constraints>                                             <constraint firstAttribute="height" constant="1" id="K5f-m2-BpE" customClass="OnePixelConstraint" customModule="segue_issue" customModuleProvider="target"/>                                         </constraints>                                     </view>                                 </subviews>                                 <color key="backgroundColor" red="0.627" green="0.114" blue="0.14099999999999999" alpha="1" colorSpace="calibratedRGB"/>                                 <constraints>                                     <constraint firstItem="Gtr-bO-frP" firstAttribute="leading" secondItem="V3o-XH-Xkn" secondAttribute="leading" id="9fX-NI-RdG"/>                                     <constraint firstAttribute="bottom" secondItem="fM3-hA-kGa" secondAttribute="bottom" id="KxS-jW-8Rh"/>                                     <constraint firstItem="fM3-hA-kGa" firstAttribute="top" secondItem="V3o-XH-Xkn" secondAttribute="top" id="VLk-U3-Dgt"/>                                     <constraint firstAttribute="trailing" secondItem="Gtr-bO-frP" secondAttribute="trailing" id="aDz-aj-8ah"/>                                     <constraint firstAttribute="trailing" secondItem="fM3-hA-kGa" secondAttribute="trailing" id="bzw-Bv-nvH"/>                                     <constraint firstAttribute="height" constant="54" id="ghd-qS-t3l"/>                                     <constraint firstItem="Gtr-bO-frP" firstAttribute="top" secondItem="V3o-XH-Xkn" secondAttribute="top" id="nZz-Tn-i7X"/>                                     <constraint firstItem="fM3-hA-kGa" firstAttribute="leading" secondItem="V3o-XH-Xkn" secondAttribute="leading" id="sxO-BS-rki"/>                                 </constraints>                             </view>                             <navigationBar contentMode="scaleToFill" translucent="NO" translatesAutoresizingMaskIntoConstraints="NO" id="SAV-Rj-fPh">                                 <rect key="frame" x="0.0" y="0.0" width="414" height="64"/>                                 <color key="barTintColor" red="0.627" green="0.114" blue="0.14099999999999999" alpha="1" colorSpace="calibratedRGB"/>                                 <textAttributes key="titleTextAttributes">                                     <fontDescription key="fontDescription" type="system" pointSize="18"/>                                     <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>                                     <offsetWrapper key="textShadowOffset" horizontal="0.0" vertical="0.0"/>                                 </textAttributes>                             </navigationBar>                             <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="NmK-Xz-xl3" userLabel="Navigation Bar Hairline">                                 <rect key="frame" x="0.0" y="64" width="414" height="1"/>                                 <color key="backgroundColor" red="0.43079092750694548" green="0.11400473755687479" blue="0.11803794560598729" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>                                 <constraints>                                     <constraint firstAttribute="height" constant="1" id="ENM-UW-O3D" customClass="OnePixelConstraint" customModule="segue_issue" customModuleProvider="target"/>                                 </constraints>                             </view>                             <button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="alk-Uo-pMv">                                 <rect key="frame" x="192" y="0.0" width="46" height="30"/>                                 <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>                                 <state key="normal" title="Button"/>                                 <connections>                                     <segue destination="G7K-pY-ZSi" kind="popoverPresentation" popoverAnchorView="alk-Uo-pMv" id="XuB-dB-CVh">                                         <popoverArrowDirection key="popoverArrowDirection" up="YES" down="YES" left="YES" right="YES"/>                                     </segue>                                 </connections>                             </button>                         </subviews>                         <constraints>                             <constraint firstItem="535-Cq-y2B" firstAttribute="leading" secondItem="xLz-jb-9OM" secondAttribute="trailing" id="0Ya-fi-fwL"/>                             <constraint firstItem="535-Cq-y2B" firstAttribute="trailing" secondItem="865-DH-bRZ" secondAttribute="trailing" id="2xc-7B-pd6"/>                             <constraint firstAttribute="trailing" secondItem="V3o-XH-Xkn" secondAttribute="trailing" id="4Qi-nQ-1b5"/>                             <constraint firstAttribute="trailing" secondItem="NmK-Xz-xl3" secondAttribute="trailing" id="4nX-tS-V49"/>                             <constraint firstAttribute="bottom" secondItem="V3o-XH-Xkn" secondAttribute="top" constant="54" id="8oE-54-0JN"/>                             <constraint firstItem="SAV-Rj-fPh" firstAttribute="top" secondItem="865-DH-bRZ" secondAttribute="top" id="DdA-dN-ucd"/>                             <constraint firstItem="V3o-XH-Xkn" firstAttribute="leading" secondItem="865-DH-bRZ" secondAttribute="leading" id="KzS-R2-JSi"/>                             <constraint firstItem="SAV-Rj-fPh" firstAttribute="bottom" secondItem="gxR-oc-l6J" secondAttribute="bottom" constant="44" id="Okf-F1-Bwv">                                 <variation key="heightClass=regular-widthClass=regular" constant="64"/>                             </constraint>                             <constraint firstItem="NmK-Xz-xl3" firstAttribute="top" secondItem="SAV-Rj-fPh" secondAttribute="bottom" id="Z7z-vD-Ypi"/>                             <constraint firstItem="SAV-Rj-fPh" firstAttribute="leading" secondItem="865-DH-bRZ" secondAttribute="leading" id="ZYY-Wz-1eh"/>                             <constraint firstAttribute="trailing" secondItem="SAV-Rj-fPh" secondAttribute="trailing" id="ein-Qv-Vwc"/>                             <constraint firstAttribute="bottom" secondItem="xLz-jb-9OM" secondAttribute="bottom" id="fmP-cS-nYy"/>                             <constraint firstItem="NmK-Xz-xl3" firstAttribute="leading" secondItem="865-DH-bRZ" secondAttribute="leading" id="nYe-rf-Zht"/>                             <constraint firstItem="xLz-jb-9OM" firstAttribute="top" secondItem="SAV-Rj-fPh" secondAttribute="bottom" id="tqI-Vx-dCH"/>                             <constraint firstAttribute="leading" secondItem="xLz-jb-9OM" secondAttribute="trailing" constant="-54" id="vuB-AY-U4j"/>                             <constraint firstItem="V3o-XH-Xkn" firstAttribute="top" secondItem="535-Cq-y2B" secondAttribute="bottom" id="wCH-Rs-saK"/>                             <constraint firstItem="535-Cq-y2B" firstAttribute="top" secondItem="SAV-Rj-fPh" secondAttribute="bottom" id="yeH-A6-JEo"/>                         </constraints>                     </view>                     <extendedEdge key="edgesForExtendedLayout"/>                     <simulatedStatusBarMetrics key="simulatedStatusBarMetrics" statusBarStyle="lightContent"/>                     <freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>                     <size key="freeformSize" width="414" height="736"/>                 </viewController>                 <placeholder placeholderIdentifier="IBFirstResponder" id="bpj-us-mEU" userLabel="First Responder" sceneMemberID="firstResponder"/>             </objects>             <point key="canvasLocation" x="681" y="-398"/>         </scene>         <!--View Controller-->         <scene sceneID="O4R-kZ-Pdk">             <objects>                 <viewController storyboardIdentifier="ContainerViewController" id="G7K-pY-ZSi" sceneMemberID="viewController">                     <layoutGuides>                         <viewControllerLayoutGuide type="top" id="ffW-Hu-TSB"/>                         <viewControllerLayoutGuide type="bottom" id="0mf-BW-Ssn"/>                     </layoutGuides>                     <view key="view" contentMode="scaleToFill" id="x2i-Md-44j">                         <rect key="frame" x="0.0" y="0.0" width="360" height="618"/>                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>                         <color key="backgroundColor" red="0.94235802664974622" green="0.91986702625601058" blue="0.90890064764795653" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>                     </view>                 </viewController>                 <placeholder placeholderIdentifier="IBFirstResponder" id="B2f-Up-4gW" userLabel="First Responder" sceneMemberID="firstResponder"/>             </objects>             <point key="canvasLocation" x="1537.68115942029" y="-398.64130434782612"/>         </scene>     </scenes>     <inferredMetricsTieBreakers>         <segue reference="XuB-dB-CVh"/>     </inferredMetricsTieBreakers>     <color key="tintColor" white="1" alpha="1" colorSpace="calibratedWhite"/> </document> 

Copy everything inside a new project, remove main as the main storyboard to launch.

  1. Run the project on an iPhone X Plus simulator (or real device).
  2. Click on the bottom to present a view controller. 2.1. Enable slow motion (simulator only).
  3. Rotate your device.

The issue I'm talking about is when the yellow view is visible (window). One rotation does layout the presenting view controller correctly, the other does begin in wrong state.

enter image description here

Is that a bug that my storyboard has or something from UIKit?

Update: The project uses latest iOS SDK and no deprecated APIs (as shown above 'almost everything is build with IB').

Update 2: I updated the original sentence to make it crystal clear that it's not a UIPopoverController.

0 Answers

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment