[英]What's the purpose of many ids in an iOS launch storyboard that just displays a simple centered image?
I have this code for an iOS launch storyboard:我有一个 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>
The code seems bloated, filled with IDs and possibly other things I do not need as all it does is display an image in the center.代码看起来很臃肿,充满了 ID 和其他可能我不需要的东西,因为它所做的只是在中心显示一个图像。
Can someone give me some suggestions on how I can clean up this code and what I could remove.有人可以就如何清理此代码以及可以删除的内容给我一些建议。
The Storyboard format is a human-readable format ( XML
) but it's not open. Storyboard 格式是一种人类可读的格式 ( XML
),但它不是开放的。 Unlike XAML
, where you can define UI layout without having a designer, Storyboards have to be created with the Storyboard designer (shipped with Xcode
).与XAML
不同,您可以在没有设计器的情况下定义 UI 布局,故事板必须使用 Storyboard 设计器(随Xcode
一起提供)创建。 I wouldn't recommend editing the Storyboard file manually in a text/xml editor because they will be overridden by the Storyboard designer once you open it.我不建议在 text/xml 编辑器中手动编辑 Storyboard 文件,因为一旦打开它们,Storyboard 设计器就会覆盖它们。
All the identifiers you see inside have an internal storyboard format defined by Apple
and used by the Storyboard designer to link elements, containers, and constraints.你在里面看到的所有标识符都有一个由Apple
定义的内部故事板格式,故事板设计者使用它来链接元素、容器和约束。
I agree that Storyboards introduce less flexibility and a lot of challenges in a multi-team-member environment because they are editable in the designer only:我同意 Storyboard 在多团队成员环境中引入较少的灵活性和很多挑战,因为它们只能在设计器中进行编辑:
Thus, from time to time you will see developers switching to code-only
approach and define the UI in the source code only ( Objective-C
or Swift
) by creating all the controls and layouts programmatically.因此,有时您会看到开发人员切换到code-only
方法,并通过以编程方式创建所有控件和布局,仅在源代码( Objective-C
或Swift
)中定义 UI。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.