我只是无法让我的应用程序在不同的屏幕尺寸上调整自己的大小.我做错了什么?



我对iOS开发(以及一般的应用程序(完全陌生。我完全不明白如何使用故事板来创建应用程序。我基本上是在尝试复制我为 Android 编写的内容并将其转换为 iOS 应用程序,但该应用程序不会在不同屏幕尺寸上调整视图大小。Android对我来说真的很容易做到,我只是觉得我被iOS淹没了。

iOS xml:

<!--Login Screen-->
<scene sceneID="4za-P4-q9T">
<objects>
<viewController title="Login Screen" id="MtT-4F-W33" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="NEA-R9-GOJ">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="right" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="Hw4-rM-kL1">
<rect key="frame" x="260" y="506" width="121" height="33"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" name="AvenirNext-Regular" family="Avenir Next" pointSize="15"/>
<state key="normal" title="Forgot Password?">
<color key="titleColor" red="0.33333334329999997" green="0.33333334329999997" blue="0.33333334329999997" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" layoutMarginsFollowReadableWidth="YES" text="Canvas Grades" lineBreakMode="tailTruncation" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="uqo-Xm-Ohe">
<rect key="frame" x="31" y="197" width="211" height="24"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<directionalEdgeInsets key="directionalLayoutMargins" top="8" leading="8" bottom="8" trailing="8"/>
<fontDescription key="fontDescription" type="system" weight="semibold" pointSize="20"/>
<color key="textColor" red="0.50980392159999999" green="0.44705882349999998" blue="0.31372549020000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" layoutMarginsFollowReadableWidth="YES" text="Highlands Latin School" lineBreakMode="tailTruncation" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Rl8-LJ-hBJ">
<rect key="frame" x="31" y="140" width="350" height="60"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<directionalEdgeInsets key="directionalLayoutMargins" top="8" leading="8" bottom="8" trailing="8"/>
<fontDescription key="fontDescription" type="system" weight="heavy" pointSize="25"/>
<color key="textColor" red="0.0" green="0.1333333333" blue="0.25098039220000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
<variation key="heightClass=regular-widthClass=compact" layoutMarginsFollowReadableWidth="YES"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="6KG-IA-18I">
<rect key="frame" x="31" y="813" width="350" height="49"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" red="0.0" green="0.1333333333" blue="0.25098039220000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<fontDescription key="fontDescription" name="AvenirNext-DemiBold" family="Avenir Next" pointSize="24"/>
<state key="normal" title="Login">
<color key="titleColor" red="0.50980392159999999" green="0.44705882349999998" blue="0.31372549020000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
</button>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" layoutMarginsFollowReadableWidth="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Email" minimumFontSize="17" clearButtonMode="whileEditing" id="meL-FW-06U">
<rect key="frame" x="31" y="431" width="350" height="34"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="tintColor" red="0.0" green="0.1333333333" blue="0.25098039220000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<edgeInsets key="layoutMargins" top="8" left="8" bottom="8" right="8"/>
<color key="textColor" red="0.0" green="0.1333333333" blue="0.25098039220000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Password" minimumFontSize="17" id="n7w-gQ-knJ">
<rect key="frame" x="32" y="473" width="350" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
</subviews>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<viewLayoutGuide key="safeArea" id="4yK-Ux-bpz"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="WjO-MG-iyw" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="62.318840579710148" y="1017.8571428571428"/>
</scene>

抱歉,如果这是一个真正的菜鸟问题,但我在网上查看,甚至使用模板来帮助我解决这个问题,但我就是做不到!约束以及如何添加它们和使用乘数对我来说毫无意义。如果视图是一张图片,我只希望从角落拖动它以水平和垂直调整大小,但将所有元素保留在相同的相对位置(SE 底部的元素应该在 Pro Max 的底部(。谢谢!

SE 底部的元素应该在 Pro Max 的底部

好吧,让我们以此为例。

您可以使用自动布局。在这种情况下,该元素需要从其超级视图的底部到底部的约束。这照顾了它的垂直位置。还需要给予它足够的约束来确定其大小和水平位置。

或者,您可以使用自动调整大小。在这种情况下,您希望支柱位于底部和右侧或左侧。

相关内容

最新更新