ios - 我在 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 很陌生,这是我第一次尝试任何东西,所以我不太清楚如何编辑由其他人创建的布局。
解决方案
选择Stack View
. 然后按command+ alt/option++更新到正确的位置。
推荐阅读
- c# - 测试括号是否平衡, (a{[]b({})}c)[] 返回 false,但应该为 true
- excel - 如何让 shell 函数读取变量中的值而不是 VBA 中的变量名?
- go - 这种错误处理是如何工作的。CSV文件读写案例
- unity3d - Sprite 显示所有帧而不像实际的 sprite
- c# - 如何防止 System.Data.SQLite ADO.NET 提供程序打开一个新文件处理每次访问数据库?
- postgresql - 如何索引 PostgreSQL 12 JSONB 列中的字段以使用 jsonb_path_match() 进行查询
- javascript - React JS 尝试导入错误:“./Pathfinder/Pathfinder”不包含默认导出(导入为“Pathfinder”)
- node.js - req.file 未定义 - multer 和 nodejs
- amazon-web-services - 将领事添加到现有的 AWS HashiCorp Vault 部署指南
- .net-core - 该请求缺少身份验证密钥。请参阅 IHttpClientFactory 的“身份验证”部分