Swift 用户界面不可滚动
我试图使我的屏幕滚动,但我不知道为什么它不滚动。我的内容视图下面有一个滚动视图,它们都受到约束。我使用的是自由形式的样式,宽度为375,高度为1000。如何使其可滚动?我错过什么了吗 以下是我对内容视图的限制Swift 用户界面不可滚动,swift,xcode,uiscrollview,autolayout,Swift,Xcode,Uiscrollview,Autolayout,我试图使我的屏幕滚动,但我不知道为什么它不滚动。我的内容视图下面有一个滚动视图,它们都受到约束。我使用的是自由形式的样式,宽度为375,高度为1000。如何使其可滚动?我错过什么了吗 以下是我对内容视图的限制 看看这个布局: 我将视图控制器的模拟大小设置为320 x 1200 红色滚动视图被限制在视图控制器上,四个侧面各有20个点,因此我们可以很容易地看到它 青色contentView被限制在scrollView的内容布局指南中,共4面8点,因此我们可以在scroll视图中看到它。它的宽度被限制
看看这个布局: 我将视图控制器的模拟大小设置为320 x 1200 红色滚动视图被限制在视图控制器上,四个侧面各有20个点,因此我们可以很容易地看到它 青色contentView被限制在scrollView的内容布局指南中,共4面8点,因此我们可以在scroll视图中看到它。它的宽度被限制在scrollView的框架布局指南中-宽度相等,每侧8个点的常数为-16 标签和按钮被约束到contentView,就像您通常做的那样 请注意,CyanContentView不是滚动视图的全高。如果增加或减少子视图的垂直约束,则ContentView的高度将相应更改。如果我增加的足够多,它将延伸到滚动视图的框架之下 当我们运行此程序时,视图控制器的高度将符合预期。。。RedScrollView还可以在每侧安装20个点。视图的高度将继续由其子视图及其约束确定 下面是这个故事板的来源,因此您可以检查并运行它,以查看没有自定义类或@IBOutlet连接的结果:
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="16096" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="A4R-eb-hDu">
<device id="retina4_0" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Start-->
<scene sceneID="7jc-VS-b5n">
<objects>
<viewController title="Start" id="MgD-bI-x2j" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="ydR-P7-HEe">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="gWd-a3-8r2">
<rect key="frame" x="79" y="269" width="184" height="30"/>
<color key="backgroundColor" red="0.92143100499999997" green="0.92145264149999995" blue="0.92144101860000005" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<state key="normal" title="Push"/>
<connections>
<segue destination="rLS-vh-BKN" kind="show" id="pNd-AG-uuu"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<constraints>
<constraint firstItem="gWd-a3-8r2" firstAttribute="leading" secondItem="ydR-P7-HEe" secondAttribute="leading" constant="79" id="219-Fb-Igc"/>
<constraint firstItem="gWd-a3-8r2" firstAttribute="centerY" secondItem="ydR-P7-HEe" secondAttribute="centerY" id="Mpd-UB-noh"/>
<constraint firstAttribute="trailing" secondItem="gWd-a3-8r2" secondAttribute="trailing" constant="57" id="rBc-wN-cex"/>
</constraints>
<viewLayoutGuide key="safeArea" id="MI0-Tc-tb9"/>
</view>
<navigationItem key="navigationItem" id="sIv-hJ-UfX"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="jhC-dV-mDd" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1686" y="1548"/>
</scene>
<!--Profitability-->
<scene sceneID="01K-FH-sRJ">
<objects>
<viewController title="Profitability" id="rLS-vh-BKN" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="a77-hQ-WPA">
<rect key="frame" x="0.0" y="0.0" width="320" height="1200"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="9oN-QK-llt" userLabel="RedScrollView">
<rect key="frame" x="20" y="64" width="280" height="1116"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="peb-CC-PPH" userLabel="CyanContentView">
<rect key="frame" x="8" y="8" width="264" height="1047"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="afB-qb-cZo" userLabel="LabelA">
<rect key="frame" x="20" y="20" width="224" height="243.5"/>
<color key="backgroundColor" red="0.99953407049999998" green="0.98835557699999999" blue="0.47265523669999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<string key="text">LabelA - with lots of text so we get word-wrapping, which will alter the height of the label itself.
Including embedded newlines / linebreaks so we have "paragraphs" in the label.
Vertical spacing constraint to LabelB is 200.</string>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="TEc-nR-a60" userLabel="LabelB">
<rect key="frame" x="20" y="463.5" width="224" height="142.5"/>
<color key="backgroundColor" red="0.99953407049999998" green="0.98835557699999999" blue="0.47265523669999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<string key="text">LabelB - also has
a couple
embedded newlines.
Vertical spacing constraint to LabelC is 200.</string>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="LabelC - Vertical spacing constraint to Button is 150." textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="xGS-cA-exz" userLabel="LabelC">
<rect key="frame" x="20" y="806" width="224" height="41"/>
<color key="backgroundColor" red="0.99953407049999998" green="0.98835557699999999" blue="0.47265523669999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="VBD-vj-jBg">
<rect key="frame" x="72" y="997" width="120" height="30"/>
<color key="backgroundColor" red="0.92143100499999997" green="0.92145264149999995" blue="0.92144101860000005" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="width" constant="120" id="1ag-JV-UEy"/>
</constraints>
<state key="normal" title="Button"/>
</button>
</subviews>
<color key="backgroundColor" red="0.45138680930000002" green="0.99309605359999997" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="VBD-vj-jBg" firstAttribute="centerX" secondItem="peb-CC-PPH" secondAttribute="centerX" id="1d6-YN-cph"/>
<constraint firstItem="VBD-vj-jBg" firstAttribute="top" secondItem="xGS-cA-exz" secondAttribute="bottom" constant="150" id="3FW-WB-UXt"/>
<constraint firstItem="afB-qb-cZo" firstAttribute="leading" secondItem="peb-CC-PPH" secondAttribute="leading" constant="20" id="R5o-XW-3a1"/>
<constraint firstAttribute="trailing" secondItem="xGS-cA-exz" secondAttribute="trailing" constant="20" id="RCd-3B-bPM"/>
<constraint firstItem="xGS-cA-exz" firstAttribute="leading" secondItem="TEc-nR-a60" secondAttribute="leading" id="bmH-dt-xMq"/>
<constraint firstItem="afB-qb-cZo" firstAttribute="top" secondItem="peb-CC-PPH" secondAttribute="top" constant="20" id="dpx-vp-wEp"/>
<constraint firstAttribute="trailing" secondItem="afB-qb-cZo" secondAttribute="trailing" constant="20" id="g5E-kL-I7Z"/>
<constraint firstAttribute="trailing" secondItem="TEc-nR-a60" secondAttribute="trailing" constant="20" id="gCE-bM-EJB"/>
<constraint firstItem="TEc-nR-a60" firstAttribute="leading" secondItem="afB-qb-cZo" secondAttribute="leading" id="jcq-9T-oxv"/>
<constraint firstItem="xGS-cA-exz" firstAttribute="top" secondItem="TEc-nR-a60" secondAttribute="bottom" constant="200" id="pLg-I8-ZkP"/>
<constraint firstAttribute="bottom" secondItem="VBD-vj-jBg" secondAttribute="bottom" constant="20" id="szQ-K9-3RQ"/>
<constraint firstItem="TEc-nR-a60" firstAttribute="top" secondItem="afB-qb-cZo" secondAttribute="bottom" constant="200" id="x3J-d3-UFv"/>
</constraints>
</view>
</subviews>
<color key="backgroundColor" red="1" green="0.14913141730000001" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="peb-CC-PPH" firstAttribute="trailing" secondItem="wHx-5k-JJS" secondAttribute="trailing" constant="8" id="5Po-m7-ffu"/>
<constraint firstItem="peb-CC-PPH" firstAttribute="width" secondItem="Qek-IK-ohW" secondAttribute="width" constant="-16" id="7MW-fv-eru"/>
<constraint firstItem="wHx-5k-JJS" firstAttribute="bottom" secondItem="peb-CC-PPH" secondAttribute="bottom" constant="8" id="PTe-0Z-R5t"/>
<constraint firstItem="peb-CC-PPH" firstAttribute="top" secondItem="wHx-5k-JJS" secondAttribute="top" constant="8" id="YGn-28-ZGV"/>
<constraint firstItem="peb-CC-PPH" firstAttribute="leading" secondItem="wHx-5k-JJS" secondAttribute="leading" constant="8" id="zcg-VU-0d5"/>
</constraints>
<viewLayoutGuide key="contentLayoutGuide" id="wHx-5k-JJS"/>
<viewLayoutGuide key="frameLayoutGuide" id="Qek-IK-ohW"/>
</scrollView>
</subviews>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<constraints>
<constraint firstItem="9oN-QK-llt" firstAttribute="leading" secondItem="c52-tu-f4c" secondAttribute="leading" constant="20" id="Cq1-vC-Sh3"/>
<constraint firstItem="9oN-QK-llt" firstAttribute="top" secondItem="c52-tu-f4c" secondAttribute="top" constant="20" id="MXd-Ur-9ct"/>
<constraint firstItem="c52-tu-f4c" firstAttribute="trailing" secondItem="9oN-QK-llt" secondAttribute="trailing" constant="20" id="ZhG-TQ-ahN"/>
<constraint firstItem="c52-tu-f4c" firstAttribute="bottom" secondItem="9oN-QK-llt" secondAttribute="bottom" constant="20" id="dA4-hq-GLX"/>
</constraints>
<viewLayoutGuide key="safeArea" id="c52-tu-f4c"/>
</view>
<navigationItem key="navigationItem" id="xZM-Uh-pzd"/>
<size key="freeformSize" width="320" height="1200"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="QYT-fW-r0T" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2557.5" y="1547.5352112676057"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="xaK-6s-98P">
<objects>
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="A4R-eb-hDu" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="w4n-sY-dwd">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
<connections>
<segue destination="MgD-bI-x2j" kind="relationship" relationship="rootViewController" id="7qE-hW-5o9"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="sxB-Bn-mKq" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="888.75" y="1547.5352112676057"/>
</scene>
</scenes>
</document>
降低高度。。设置内容大小增加什么的高度?看起来您正在将内容视图的高度设置为:Superview。。。这是您不想要的,因为superview是滚动视图。如果删除该约束,是否会滚动?如果删除该约束,则不会使其滚动。我让scrollview与我的一些UI一起工作,但它们太相似了,我很难弄清楚这一个出现了什么问题。