首页 > 解决方案 > 我在 iOS 中使用 Visual Designer 作为 View Controller 初始屏幕,但图像没有出现在中心

问题描述

以下是设计师展示的内容:

在此处输入图像描述

由于可能不清楚,我将在下面添加 XML:

<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="16096" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
    <device id="retina6_1" orientation="portrait" appearance="light"/>
    <dependencies>
        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16086"/>
        <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="EHf-IW-A2E">
            <objects>
                <viewController id="01J-lp-oVM" sceneMemberID="viewController">
                    <view key="view" contentMode="center" id="Ze5-6b-2t3">
                        <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" misplaced="YES" axis="vertical" distribution="equalCentering" alignment="center" spacing="20" translatesAutoresizingMaskIntoConstraints="NO" id="Zbh-CC-wDS">
                                <rect key="frame" x="107" y="294" width="128" height="136"/>
                                <subviews>
                                    <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="splash_image.png" translatesAutoresizingMaskIntoConstraints="NO" id="znN-uk-H0B">
                                        <rect key="frame" x="0.0" y="0.0" width="128" height="80"/>
                                        <constraints>
                                            <constraint firstAttribute="height" constant="80" id="A2X-j1-ymP"/>
                                        </constraints>
                                    </imageView>
                                    <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="ABC" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="EcF-nC-k2o" colorLabel="IBBuiltInLabel-Gray">
                                        <rect key="frame" x="34.5" y="100" width="59" height="36"/>
                                        <fontDescription key="fontDescription" type="system" pointSize="30"/>
                                        <color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
                                        <nil key="highlightedColor"/>
                                    </label>
                                </subviews>
                            </stackView>
                        </subviews>
                        <color key="backgroundColor" red="0.20000000000000001" green="0.20000000000000001" blue="0.20000000000000001" alpha="1" colorSpace="calibratedRGB"/>
                        <constraints>
                            <constraint firstItem="Zbh-CC-wDS" firstAttribute="centerX" secondItem="Ze5-6b-2t3" secondAttribute="centerX" id="eih-d4-foy"/>
                            <constraint firstItem="Zbh-CC-wDS" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="centerY" constant="-60" id="fGG-ZZ-u69"/>
                        </constraints>
                        <viewLayoutGuide key="safeArea" id="wza-7a-P1J"/>
                    </view>
                </viewController>
                <placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
            </objects>
            <point key="canvasLocation" x="1347.826" y="610.71429999999998"/>
        </scene>
    </scenes>
    <resources>
        <image name="splash_image.png" width="128" height="128"/>
    </resources>
</document>

是否以正确的方式进行居中?也许通过查看 XML 可能会发现问题。

它表明它不在中心,但我不知道为什么。

我对 iOS 很陌生,这是我第一次尝试任何东西,所以我不太清楚如何编辑由其他人创建的布局。

标签: iosswiftxcodeuiviewcontrolleruicollectionview

解决方案


选择Stack View. 然后按command+ alt/option++更新到正确的位置。


推荐阅读