我创建了一个UIViewController
,其中包含一个UIStackView
。然后,我从“界面生成器”中拖动了2个单独的“容器视图”对象,并将它们放在UIStackView
中。我将所有内容设置为显示相等的大小,如下所示,一切看起来都很好。
然后,我尝试将左侧的UIViewController
嵌入到UITabBarController
中,而右侧的UIViewController嵌入到UINavigationController
中。当我这样做时,UITabBarController
本身可以正确渲染,但是没有其他可以渲染。您在第一张图片中看到的“右侧儿童VC” /“左侧儿童VC” UILabel
不会出现。另外,我希望在右侧UINavigationBar
/ UINavigationController
中看到的UIViewController
根本没有呈现。 (见下文)
这不是受支持的视图层次结构吗?还是在草绘UI时缺少某些内容?这是一个非常简单的设置,所以我确定我在这里一定做错了。我只是不知道是什么。有什么想法吗?
答案 0 :(得分:0)
布局应该没有问题。我建议您从头开始,或者只是仔细查看您要尝试找出问题的方式。
这是我刚才做的一个例子:
这是情节提要的源代码(根本不使用任何代码)。也许会帮助您找到问题所在:
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="a3E-zy-HPT">
<device id="ipad9_7" orientation="landscape">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="b2n-7J-CgC">
<objects>
<viewController id="a3E-zy-HPT" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="KZ3-dF-um0">
<rect key="frame" x="0.0" y="0.0" width="1024" height="768"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="20" translatesAutoresizingMaskIntoConstraints="NO" id="isF-Am-gyT">
<rect key="frame" x="20" y="40" width="984" height="708"/>
<subviews>
<containerView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="tSf-1c-DXK">
<rect key="frame" x="0.0" y="0.0" width="482" height="708"/>
<connections>
<segue destination="a6c-TQ-han" kind="embed" id="wJI-Oa-9d8"/>
</connections>
</containerView>
<containerView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Cbg-8F-i9g">
<rect key="frame" x="502" y="0.0" width="482" height="708"/>
<connections>
<segue destination="j5j-RN-MXn" kind="embed" id="xcH-30-iu7"/>
</connections>
</containerView>
</subviews>
</stackView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="isF-Am-gyT" firstAttribute="top" secondItem="6ov-Cy-Ir7" secondAttribute="top" constant="20" id="USK-a7-tSI"/>
<constraint firstItem="6ov-Cy-Ir7" firstAttribute="bottom" secondItem="isF-Am-gyT" secondAttribute="bottom" constant="20" id="VsI-nn-Lkr"/>
<constraint firstItem="6ov-Cy-Ir7" firstAttribute="trailing" secondItem="isF-Am-gyT" secondAttribute="trailing" constant="20" id="XCt-l8-Yb9"/>
<constraint firstItem="isF-Am-gyT" firstAttribute="leading" secondItem="6ov-Cy-Ir7" secondAttribute="leading" constant="20" id="oyc-rl-VH4"/>
</constraints>
<viewLayoutGuide key="safeArea" id="6ov-Cy-Ir7"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="E22-5h-DVF" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="122" y="107"/>
</scene>
<!--View Controller-->
<scene sceneID="0NG-jb-kKA">
<objects>
<viewController id="aUN-mz-OsG" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="TYT-qP-0f7">
<rect key="frame" x="0.0" y="0.0" width="482" height="708"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Nav Root VC" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="jot-50-nWz">
<rect key="frame" x="153" y="334.5" width="176" height="39"/>
<fontDescription key="fontDescription" type="system" pointSize="32"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" red="1" green="0.83234566450000003" blue="0.47320586440000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="jot-50-nWz" firstAttribute="centerY" secondItem="TYT-qP-0f7" secondAttribute="centerY" id="28z-MT-YCI"/>
<constraint firstItem="jot-50-nWz" firstAttribute="centerX" secondItem="TYT-qP-0f7" secondAttribute="centerX" id="Gi7-4Y-AjH"/>
</constraints>
<viewLayoutGuide key="safeArea" id="RRI-ma-q1W"/>
</view>
<navigationItem key="navigationItem" id="hOU-IQ-1El"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="SbD-h6-Vqx" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="754" y="798"/>
</scene>
<!--Item 2-->
<scene sceneID="2wS-Zh-sav">
<objects>
<viewController id="Eti-JO-pq9" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="HfC-oh-jte">
<rect key="frame" x="0.0" y="0.0" width="482" height="708"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Second Tab" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="acL-vG-z3l">
<rect key="frame" x="160.5" y="335" width="161.5" height="38.5"/>
<fontDescription key="fontDescription" type="system" pointSize="32"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" red="0.46202266219999999" green="0.83828371759999998" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="acL-vG-z3l" firstAttribute="centerX" secondItem="HfC-oh-jte" secondAttribute="centerX" id="2Oh-Nh-GJB"/>
<constraint firstItem="acL-vG-z3l" firstAttribute="centerY" secondItem="HfC-oh-jte" secondAttribute="centerY" id="q1E-kw-utV"/>
</constraints>
<viewLayoutGuide key="safeArea" id="Biq-1g-K08"/>
</view>
<tabBarItem key="tabBarItem" title="Item 2" id="RQo-7T-lpL"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="uxd-vy-6z6" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="122" y="1485"/>
</scene>
<!--Item 1-->
<scene sceneID="lGr-eZ-se1">
<objects>
<viewController id="PIq-bk-5i9" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="5EA-RT-arW">
<rect key="frame" x="0.0" y="0.0" width="482" height="708"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="First Tab" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="MqF-oN-08O">
<rect key="frame" x="183" y="335" width="116" height="38.5"/>
<fontDescription key="fontDescription" type="system" pointSize="32"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" red="0.83216959239999999" green="0.98548370600000001" blue="0.47333085539999997" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="MqF-oN-08O" firstAttribute="centerY" secondItem="5EA-RT-arW" secondAttribute="centerY" id="adF-hp-Zru"/>
<constraint firstItem="MqF-oN-08O" firstAttribute="centerX" secondItem="5EA-RT-arW" secondAttribute="centerX" id="kBQ-9K-Y1g"/>
</constraints>
<viewLayoutGuide key="safeArea" id="48X-sh-gIQ"/>
</view>
<tabBarItem key="tabBarItem" title="Item 1" id="tNF-6e-qoJ"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="uHV-RY-oqY" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-372" y="1473"/>
</scene>
<!--Tab Bar Controller-->
<scene sceneID="C5L-yQ-vn8">
<objects>
<tabBarController id="a6c-TQ-han" sceneMemberID="viewController">
<tabBar key="tabBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="pkv-HU-5fb">
<rect key="frame" x="0.0" y="0.0" width="375" height="49"/>
<autoresizingMask key="autoresizingMask"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</tabBar>
<connections>
<segue destination="PIq-bk-5i9" kind="relationship" relationship="viewControllers" id="3EH-dA-L0h"/>
<segue destination="Eti-JO-pq9" kind="relationship" relationship="viewControllers" id="tvF-0L-zgq"/>
</connections>
</tabBarController>
<placeholder placeholderIdentifier="IBFirstResponder" id="2cT-d5-vXz" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-132" y="798"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="O3Z-Ku-kaQ">
<objects>
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="j5j-RN-MXn" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="EXg-9E-uJx">
<rect key="frame" x="0.0" y="20" width="482" height="50"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
<connections>
<segue destination="aUN-mz-OsG" kind="relationship" relationship="rootViewController" id="Bp8-wj-NyV"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="TH6-8z-qVz" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="411" y="798"/>
</scene>
</scenes>
</document>