ios - 我只是无法让我的应用程序在不同的屏幕尺寸上自行调整大小。我究竟做错了什么?

标签 ios iphone autolayout storyboard ios-autolayout

我完全不熟悉 iOS 开发(以及制作应用程序)。我完全不明白如何使用 Storyboard 来创建应用程序。我基本上是在尝试复制我为 Android 编写的内容并将其转换为 iOS 应用程序,但该应用程序不会在不同的屏幕尺寸上调整 View 的大小。 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>

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

最佳答案

element at the bottom on an SE should be at the bottom on Pro Max

好吧,让我们以此为例。

您可以使用自动布局。在那种情况下,该元素需要从其底部到其父 View 底部的约束。这会处理它的垂直位置。它还需要给予足够的约束来确定其大小和水平位置。

或者,您可以使用自动调整大小。在那种情况下,您需要在底部和右侧或左侧放置支柱。

关于ios - 我只是无法让我的应用程序在不同的屏幕尺寸上自行调整大小。我究竟做错了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59831809/

相关文章:

xcode - 如何在 Interface Builder 中向 NSTextField 的基线添加约束?

ios - collectionView 无法在当前场景重新加载 ItemsAtIndexPaths

ios - UIScrollView/UITableView 分层效果如Path

objective-c - 在 UIBezierPath addLineToPoint 的末尾运行一些代码

ios - CLLocationManager 初始更新不太准确

iphone - 通过核心数据计算小数值的总和无法正常工作?

iPhone iOS7系统声音(铃声和提醒)音量控制

iphone - 检查 MBProgressHUD 状态是否隐藏/显示

ios - ScrollView 不会在 Swift 中使用 AutoLayout 垂直滚动内容

ios - 使用自动布局时计算 UIScrollView 的 contentSize