切换到垂直轴时堆栈视图中断

时间:2021-06-02 06:26:25

标签: swift xml constraints

作为 this 问题的延续。当我在 ViewController 中实际应用约束时,我发现实际上将轴切换到 Vertical 完全打破了约束。

这是以前的。看起来很合适。

enter image description here

现在是切换到垂直后。

enter image description here

完全不明白为什么会这样......

enter image description here

它说我需要另一个宽度约束,但是堆栈视图已经有 2 个宽度约束:

enter image description here

为什么会发生这种情况,我该如何解决?

这是我的代码:


<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="18122" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
    <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>
    <scenes>
        <!--View Controller-->
        <scene sceneID="tne-QT-ifu">
            <objects>
                <viewController id="BYZ-38-t0r" customClass="ViewController" customModule="Test2Part" customModuleProvider="target" sceneMemberID="viewController">
                    <view key="view" contentMode="scaleToFill" ambiguous="YES" id="8bC-Xf-vdC">
                        <rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
                        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                        <subviews>
                            <stackView opaque="NO" contentMode="scaleToFill" ambiguous="YES" axis="vertical" spacing="7" translatesAutoresizingMaskIntoConstraints="NO" id="VP4-UJ-ETA">
                                <rect key="frame" x="0.0" y="424" width="0.0" height="48"/>
                                <subviews>
                                    <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="1000" verticalHuggingPriority="1000" text="asdlfkjlkjalskdjflakjsdlkfjalkjsdflkjasldkfjalkjsdflkj" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Xej-eS-5Sd">
                                        <rect key="frame" x="0.0" y="0.0" width="0.0" height="20.5"/>
                                        <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" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Xj4-8Q-inE">
                                        <rect key="frame" x="0.0" y="27.5" width="0.0" height="20.5"/>
                                        <string key="text">asldkfjalkjsdflkjasldkjfalkjsdflkjasldkjflakjsdlfkjalskdjflaqkjsdlfkjalksdjflaksdlfkjalskdjflakjsdlfkjalsdkjflakjsdflkjasldkjflakjsdflkjasdf</string>
                                        <fontDescription key="fontDescription" type="system" pointSize="17"/>
                                        <nil key="textColor"/>
                                        <nil key="highlightedColor"/>
                                    </label>
                                </subviews>
                                <constraints>
                                    <constraint firstItem="Xj4-8Q-inE" firstAttribute="width" relation="greaterThanOrEqual" secondItem="Xej-eS-5Sd" secondAttribute="width" multiplier="1.2" id="xrh-Tq-uYT"/>
                                </constraints>
                            </stackView>
                        </subviews>
                        <viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
                        <color key="backgroundColor" systemColor="systemBackgroundColor"/>
                        <constraints>
                            <constraint firstItem="VP4-UJ-ETA" firstAttribute="centerY" secondItem="8bC-Xf-vdC" secondAttribute="centerY" id="ML4-KP-VmW"/>
                            <constraint firstItem="VP4-UJ-ETA" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="ZUI-PV-Ofm"/>
                            <constraint firstItem="VP4-UJ-ETA" firstAttribute="width" secondItem="8bC-Xf-vdC" secondAttribute="width" id="aA4-hD-Jye"/>
                        </constraints>
                    </view>
                </viewController>
                <placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
            </objects>
            <point key="canvasLocation" x="26" y="89"/>
        </scene>
    </scenes>
    <resources>
        <systemColor name="systemBackgroundColor">
            <color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
        </systemColor>
    </resources>
</document>

0 个答案:

没有答案