当堆栈视图中的堆栈视图高度明确时,需要对 y 位置或高度进行约束

Need constraints for y position or height when height is unambiguous with stack views in stack views

我在下面创建了一个“TitleDetails”视图,我想将该 titleDetails 视图堆叠到另一个可重用视图中。 TitleDetails 约束没有抛出任何错误。我只想将 2 个 TitleDetails 视图堆叠到一个新视图中。

但是,当我进行约束时,似乎我需要高度的 Y 位置,但是 titleDetails 的高度应由其内容决定,并且两者之间的 space 也受到约束。所以我看不出歧义是从哪里来的。

<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="18122" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
    <device id="retina6_1" orientation="portrait" appearance="light"/>
    <dependencies>
        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
        <capability name="Safe area layout guides" minToolsVersion="9.0"/>
        <capability name="System colors in document resources" minToolsVersion="11.0"/>
        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
    </dependencies>
    <objects>
        <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="TitleDetails" customModule="WholeVC" customModuleProvider="target">
            <connections>
                <outlet property="detailsLabel" destination="pjO-IR-TuP" id="EkZ-wc-LOm"/>
                <outlet property="stackBottom" destination="W1y-Me-M1S" id="ykw-d7-bz9"/>
                <outlet property="stackLeading" destination="6n3-Qg-845" id="ghK-h8-OBL"/>
                <outlet property="stackTop" destination="Ey8-Pq-GRr" id="WOw-Q0-zc2"/>
                <outlet property="stackTrailing" destination="m9b-I7-Nwj" id="ly8-lY-3zf"/>
                <outlet property="stackView" destination="pIM-2q-cOU" id="LvK-Yk-LHf"/>
                <outlet property="titleLabel" destination="G5U-AG-1Se" id="4KM-9f-LQA"/>
            </connections>
        </placeholder>
        <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
        <view contentMode="scaleToFill" id="iN0-l3-epB">
            <rect key="frame" x="0.0" y="0.0" width="208" height="72"/>
            <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
            <subviews>
                <stackView opaque="NO" contentMode="scaleToFill" spacing="5" translatesAutoresizingMaskIntoConstraints="NO" id="pIM-2q-cOU">
                    <rect key="frame" x="0.0" y="0.0" width="208" height="72"/>
                    <subviews>
                        <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="1000" verticalHuggingPriority="1000" text="Title" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="G5U-AG-1Se">
                            <rect key="frame" x="0.0" y="0.0" width="36.5" height="72"/>
                            <fontDescription key="fontDescription" type="boldSystem" pointSize="17"/>
                            <nil key="textColor"/>
                            <nil key="highlightedColor"/>
                        </label>
                        <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Details Details Details" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="pjO-IR-TuP">
                            <rect key="frame" x="41.5" y="0.0" width="166.5" height="72"/>
                            <fontDescription key="fontDescription" type="system" pointSize="17"/>
                            <nil key="textColor"/>
                            <nil key="highlightedColor"/>
                        </label>
                    </subviews>
                    <constraints>
                        <constraint firstItem="pjO-IR-TuP" firstAttribute="width" relation="greaterThanOrEqual" secondItem="G5U-AG-1Se" secondAttribute="width" id="EGR-ZT-2ID"/>
                    </constraints>
                </stackView>
            </subviews>
            <viewLayoutGuide key="safeArea" id="vUN-kp-3ea"/>
            <color key="backgroundColor" systemColor="systemBackgroundColor"/>
            <constraints>
                <constraint firstItem="pIM-2q-cOU" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" id="6n3-Qg-845"/>
                <constraint firstItem="pIM-2q-cOU" firstAttribute="top" secondItem="iN0-l3-epB" secondAttribute="top" id="Ey8-Pq-GRr"/>
                <constraint firstAttribute="bottom" secondItem="pIM-2q-cOU" secondAttribute="bottom" id="W1y-Me-M1S"/>
                <constraint firstAttribute="trailing" secondItem="pIM-2q-cOU" secondAttribute="trailing" id="m9b-I7-Nwj"/>
            </constraints>
            <freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
            <point key="canvasLocation" x="94.20289855072464" y="-113.16964285714285"/>
        </view>
        <view contentMode="scaleToFill" id="Xof-7G-Flv">
            <rect key="frame" x="0.0" y="0.0" width="355" height="279"/>
            <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
            <subviews>
                <view contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="awM-nF-Vev" customClass="TitleDetails" customModule="WholeVC" customModuleProvider="target">
                    <rect key="frame" x="0.0" y="0.0" width="355" height="103"/>
                    <color key="backgroundColor" systemColor="systemBackgroundColor"/>
                </view>
                <view contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="mcx-Fg-GMg" customClass="TitleDetails" customModule="WholeVC" customModuleProvider="target">
                    <rect key="frame" x="0.0" y="172" width="355" height="107"/>
                    <color key="backgroundColor" systemColor="systemBackgroundColor"/>
                </view>
            </subviews>
            <viewLayoutGuide key="safeArea" id="art-6S-teo"/>
            <color key="backgroundColor" systemColor="systemBackgroundColor"/>
            <constraints>
                <constraint firstItem="awM-nF-Vev" firstAttribute="leading" secondItem="Xof-7G-Flv" secondAttribute="leading" id="3Sp-vC-vfu"/>
                <constraint firstItem="awM-nF-Vev" firstAttribute="trailing" secondItem="Xof-7G-Flv" secondAttribute="trailing" id="L4H-5I-T0j"/>
                <constraint firstItem="awM-nF-Vev" firstAttribute="top" secondItem="Xof-7G-Flv" secondAttribute="top" id="Xcm-9t-hJx"/>
                <constraint firstItem="mcx-Fg-GMg" firstAttribute="top" secondItem="awM-nF-Vev" secondAttribute="bottom" constant="69" id="Yh4-pM-WP6"/>
                <constraint firstItem="mcx-Fg-GMg" firstAttribute="trailing" secondItem="Xof-7G-Flv" secondAttribute="trailing" id="dUB-H0-Zm1"/>
                <constraint firstItem="mcx-Fg-GMg" firstAttribute="bottom" secondItem="Xof-7G-Flv" secondAttribute="bottom" id="feT-Rh-Vs7"/>
                <constraint firstItem="mcx-Fg-GMg" firstAttribute="leading" secondItem="Xof-7G-Flv" secondAttribute="leading" id="pD5-5k-VJf"/>
            </constraints>
            <freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
            <point key="canvasLocation" x="94.927536231884062" y="67.96875"/>
        </view>
    </objects>
    <resources>
        <systemColor name="systemBackgroundColor">
            <color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
        </systemColor>
    </resources>
</document>

您展示的内容很容易通过代码实现,而不是 XIB 文件。

但是,您出现歧义的原因是界面生成器无法确定您设计的固有高度。

IF 您当前的实现在 运行 时为您提供了所需的布局,您可以摆脱“通过给您的顶部 TitleDetails 视图一个“占位符”固有高度来发出“模棱两可”的错误/警告。

Select 视图,然后在“大小检查器”窗格中: