IOS滚动视图在设计时是否在故事板中可滚动?模拟器中没有运行时

Is IOS Scroll View is Scrollable in Storyboard while Designing? Not Runtime in Simulator

提问人:Ankur Pipaliya 提问时间:7/4/2022 最后编辑:FogmeisterAnkur Pipaliya 更新时间:7/11/2022 访问量:291

问:

在故事板中,我有视图控制器,里面有一个滚动视图。问题是 scrollview 在设计时不可滚动 (UIKit)。是这样吗?不过,它在模拟器中工作正常。Inage

iOS iPhone UIscrollView Storyboard Interface-Builder

评论


答:

-1赞 DarkDust 7/4/2022 #1

Interface Builder(用于构建 XIB 和 Storyboard)不是“实时”的,您无法像使用 SwiftUI 预览的“实时”模式那样与 UI 元素进行交互。这也意味着您无法滚动滚动视图。

0赞 DonMag 7/8/2022 #2

如果您正确设置了约束,当然,您可以在 Storyboard / Interface Builder 中滚动。

只需选择滚动视图的任何子视图,就可以像滚动其他任何内容(例如此网页)一样滚动。

在这里,我有一个堆栈视图,其中包含多个标签和按钮,在滚动视图中:

enter image description here

我选择了堆栈视图,如您所见,我可以滚动内容:

enter image description here


编辑 - 没有堆栈视图的示例:

enter image description here

enter image description here

enter image description here

情节提要源

<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="20037" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
    <device id="retina4_0" orientation="portrait" appearance="light"/>
    <dependencies>
        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/>
        <capability name="Safe area layout guides" minToolsVersion="9.0"/>
        <capability name="System colors in document resources" minToolsVersion="11.0"/>
        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
    </dependencies>
    <scenes>
        <!--View Controller-->
        <scene sceneID="R32-dA-683">
            <objects>
                <viewController id="vD2-wr-GKn" sceneMemberID="viewController">
                    <view key="view" contentMode="scaleToFill" id="nx6-KC-Ism">
                        <rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
                        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                        <subviews>
                            <scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="iRw-uR-kHf">
                                <rect key="frame" x="29" y="80" width="262" height="200"/>
                                <subviews>
                                    <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="These are NOT in a stack view." textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="2gt-3M-hxU" userLabel="TopLabel">
                                        <rect key="frame" x="12" y="12" width="238" height="57.5"/>
                                        <color key="backgroundColor" red="0.66847345069999997" green="0.96944552660000005" blue="0.92393370939999997" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
                                        <fontDescription key="fontDescription" type="system" pointSize="24"/>
                                        <nil key="textColor"/>
                                        <nil key="highlightedColor"/>
                                    </label>
                                    <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="XQI-7T-dgO">
                                        <rect key="frame" x="12" y="89.5" width="238" height="34"/>
                                        <color key="backgroundColor" red="1" green="0.1857388616" blue="0.57339501380000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                                        <inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
                                        <state key="normal" title="Button 1"/>
                                    </button>
                                    <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label 1" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="xM5-9u-L9O">
                                        <rect key="frame" x="12" y="143.5" width="238" height="29"/>
                                        <color key="backgroundColor" red="0.66847345069999997" green="0.96944552660000005" blue="0.92393370939999997" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
                                        <fontDescription key="fontDescription" type="system" pointSize="24"/>
                                        <nil key="textColor"/>
                                        <nil key="highlightedColor"/>
                                    </label>
                                    <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="8Xy-ME-rrn">
                                        <rect key="frame" x="12" y="192.5" width="238" height="34"/>
                                        <color key="backgroundColor" red="1" green="0.1857388616" blue="0.57339501380000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                                        <inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
                                        <state key="normal" title="Button 2"/>
                                    </button>
                                    <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label 2" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="cmo-bX-Wha">
                                        <rect key="frame" x="12" y="246.5" width="238" height="29"/>
                                        <color key="backgroundColor" red="0.66847345069999997" green="0.96944552660000005" blue="0.92393370939999997" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
                                        <fontDescription key="fontDescription" type="system" pointSize="24"/>
                                        <nil key="textColor"/>
                                        <nil key="highlightedColor"/>
                                    </label>
                                    <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="oJQ-EN-Pc2">
                                        <rect key="frame" x="12" y="295.5" width="238" height="34"/>
                                        <color key="backgroundColor" red="1" green="0.1857388616" blue="0.57339501380000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                                        <inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
                                        <state key="normal" title="Button 3"/>
                                    </button>
                                    <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label 3" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="qbm-Ls-5bH">
                                        <rect key="frame" x="12" y="349.5" width="238" height="29"/>
                                        <color key="backgroundColor" red="0.66847345069999997" green="0.96944552660000005" blue="0.92393370939999997" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
                                        <fontDescription key="fontDescription" type="system" pointSize="24"/>
                                        <nil key="textColor"/>
                                        <nil key="highlightedColor"/>
                                    </label>
                                </subviews>
                                <constraints>
                                    <constraint firstItem="XQI-7T-dgO" firstAttribute="top" secondItem="2gt-3M-hxU" secondAttribute="bottom" constant="20" id="1JB-jn-Y1A"/>
                                    <constraint firstItem="8Xy-ME-rrn" firstAttribute="trailing" secondItem="2gt-3M-hxU" secondAttribute="trailing" id="5xk-GB-AXw"/>
                                    <constraint firstItem="qbm-Ls-5bH" firstAttribute="leading" secondItem="2gt-3M-hxU" secondAttribute="leading" id="Fvr-yK-lDT"/>
                                    <constraint firstAttribute="height" constant="200" id="Ihy-yc-MRl"/>
                                    <constraint firstItem="cmo-bX-Wha" firstAttribute="top" secondItem="8Xy-ME-rrn" secondAttribute="bottom" constant="20" id="Iin-6N-3gO"/>
                                    <constraint firstItem="xM5-9u-L9O" firstAttribute="top" secondItem="XQI-7T-dgO" secondAttribute="bottom" constant="20" id="J9M-zb-NzA"/>
                                    <constraint firstItem="qbm-Ls-5bH" firstAttribute="trailing" secondItem="2gt-3M-hxU" secondAttribute="trailing" id="Kde-rB-mb0"/>
                                    <constraint firstItem="2gt-3M-hxU" firstAttribute="top" secondItem="QXL-qb-619" secondAttribute="top" constant="12" id="Ntt-xH-QjE"/>
                                    <constraint firstItem="8Xy-ME-rrn" firstAttribute="top" secondItem="xM5-9u-L9O" secondAttribute="bottom" constant="20" id="Pwf-RD-jiR"/>
                                    <constraint firstItem="qbm-Ls-5bH" firstAttribute="bottom" secondItem="QXL-qb-619" secondAttribute="bottom" constant="-12" id="Svr-fK-RCS"/>
                                    <constraint firstItem="cmo-bX-Wha" firstAttribute="trailing" secondItem="2gt-3M-hxU" secondAttribute="trailing" id="Ybg-lo-eZf"/>
                                    <constraint firstItem="xM5-9u-L9O" firstAttribute="leading" secondItem="2gt-3M-hxU" secondAttribute="leading" id="cG2-4v-Nhr"/>
                                    <constraint firstItem="8Xy-ME-rrn" firstAttribute="leading" secondItem="2gt-3M-hxU" secondAttribute="leading" id="ckZ-hn-bLA"/>
                                    <constraint firstItem="XQI-7T-dgO" firstAttribute="leading" secondItem="2gt-3M-hxU" secondAttribute="leading" id="ddl-OY-kTY"/>
                                    <constraint firstItem="oJQ-EN-Pc2" firstAttribute="trailing" secondItem="2gt-3M-hxU" secondAttribute="trailing" id="eLH-pR-rdE"/>
                                    <constraint firstItem="2gt-3M-hxU" firstAttribute="trailing" secondItem="QXL-qb-619" secondAttribute="trailing" constant="12" id="ePZ-Uj-mk4"/>
                                    <constraint firstItem="XQI-7T-dgO" firstAttribute="trailing" secondItem="2gt-3M-hxU" secondAttribute="trailing" id="hIQ-js-aEj"/>
                                    <constraint firstItem="qbm-Ls-5bH" firstAttribute="top" secondItem="oJQ-EN-Pc2" secondAttribute="bottom" constant="20" id="jNx-LZ-ynL"/>
                                    <constraint firstItem="oJQ-EN-Pc2" firstAttribute="leading" secondItem="2gt-3M-hxU" secondAttribute="leading" id="kw8-Ms-6YK"/>
                                    <constraint firstItem="2gt-3M-hxU" firstAttribute="width" secondItem="Qga-bs-KPf" secondAttribute="width" constant="-24" id="pNe-nW-Yzd"/>
                                    <constraint firstItem="xM5-9u-L9O" firstAttribute="trailing" secondItem="2gt-3M-hxU" secondAttribute="trailing" id="pUa-cV-nnJ"/>
                                    <constraint firstItem="cmo-bX-Wha" firstAttribute="leading" secondItem="2gt-3M-hxU" secondAttribute="leading" id="qNj-RD-4sl"/>
                                    <constraint firstItem="2gt-3M-hxU" firstAttribute="leading" secondItem="QXL-qb-619" secondAttribute="leading" constant="12" id="qXU-fl-OTt"/>
                                    <constraint firstItem="oJQ-EN-Pc2" firstAttribute="top" secondItem="cmo-bX-Wha" secondAttribute="bottom" constant="20" id="ucE-MC-AnG"/>
                                </constraints>
                                <viewLayoutGuide key="contentLayoutGuide" id="QXL-qb-619"/>
                                <viewLayoutGuide key="frameLayoutGuide" id="Qga-bs-KPf"/>
                            </scrollView>
                        </subviews>
                        <viewLayoutGuide key="safeArea" id="OhM-Cg-QZj"/>
                        <color key="backgroundColor" systemColor="systemBackgroundColor"/>
                        <constraints>
                            <constraint firstItem="iRw-uR-kHf" firstAttribute="top" secondItem="OhM-Cg-QZj" secondAttribute="top" constant="80" id="EH1-J3-Hha"/>
                            <constraint firstItem="iRw-uR-kHf" firstAttribute="leading" secondItem="OhM-Cg-QZj" secondAttribute="leading" constant="29" id="LKa-pv-cz5"/>
                            <constraint firstAttribute="trailing" secondItem="iRw-uR-kHf" secondAttribute="trailing" constant="29" id="xW2-T3-k3K"/>
                        </constraints>
                    </view>
                </viewController>
                <placeholder placeholderIdentifier="IBFirstResponder" id="1GU-I7-lw5" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
            </objects>
            <point key="canvasLocation" x="-789.375" y="214.43661971830986"/>
        </scene>
    </scenes>
    <resources>
        <systemColor name="systemBackgroundColor">
            <color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
        </systemColor>
    </resources>
</document>

评论

0赞 Ankur Pipaliya 7/11/2022
我们可以在不使用堆栈视图的情况下做到这一点吗?
0赞 DonMag 7/11/2022
@AnkurPipaliya - 当然......只要您的约束设置正确。请参阅编辑我的答案。