仅显示简单居中图像的iOS启动情节提要中许多ID的目的是什么?

问题描述 投票:1回答:1

我有用于iOS启动故事板的代码:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15505" 
          targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" 
          useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
    <device id="retina5_5" orientation="portrait" appearance="light"/>
    <dependencies>
        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15509"/>
        <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">
                    <layoutGuides>
                        <viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
                        <viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
                    </layoutGuides>
                    <view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
                        <rect key="frame" x="0.0" y="0.0" width="414" height="736"/>
                        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                        <subviews>
                            <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="LaunchIcon" translatesAutoresizingMaskIntoConstraints="NO" id="1864">
                                <rect key="frame" x="131" y="292" width="152" height="152"/>
                                <constraints>
                                    <constraint firstAttribute="width" constant="152" id="2074"/>
                                    <constraint firstAttribute="height" constant="152" id="2075"/>
                                </constraints>
                            </imageView>
                        </subviews>
                        <color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
                        <constraints>
                            <constraint firstItem="1864" firstAttribute="centerX" secondItem="Ze5-6b-2t3" secondAttribute="centerX" id="2284"/>
                            <constraint firstAttribute="centerY" secondItem="1864" secondAttribute="centerY" id="2285"/>
                        </constraints>
                    </view>
                </viewController>
                <placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
            </objects>
            <point key="canvasLocation" x="53" y="375"/>
        </scene>
    </scenes>
</document>

该代码看起来很肿,充满了ID和其他可能我不需要的东西,因为它所做的只是在中间显示图像。

有人可以给我一些有关如何清理此代码以及删除的建议。

ios xcode uistoryboard xcode-storyboard
1个回答
0
投票

故事板格式是一种人类可读的格式(XML),但未打开。与XAML不同,您可以在没有设计师的情况下定义UI布局,而Storyboard则必须由Storyboard设计器(随Xcode一起提供)创建。我不建议在文本/ xml编辑器中手动编辑Storyboard文件,因为一旦打开它,Storyboard设计器将覆盖它们。

您在内部看到的所有标识符都具有由Apple定义的内部情节提要格式,并且由情节提要设计者用于链接元素,容器和约束。

我同意情节提要板在多团队成员环境中会带来较小的灵活性和很多挑战,因为它们只能在设计器中进行编辑:

  • 一个人可以一次介绍更改
  • 解决冲突
  • 更改跟踪

因此,您将不时看到开发人员切换到code-only方法,并通过以编程方式创建所有控件和布局来仅在源代码(Objective-CSwift)中定义UI。

© www.soinside.com 2019 - 2024. All rights reserved.