在下面的截圖中,藍色區域是我的UIScrollView,黃色區域是UIView組件。使一個UIView組件向上和向下滾動
我想達到什麼是隻有黃色區域可以倒在iPhone上移和。 (我將在黃色的UIView上添加更多的UI組件,它們應該作爲一個整體移動/滾動)
我現在陷入困境,我不確定我是否處於實現它的正確方向。有人能指導我正確的方向嗎?
(我還需要改變藍色背景,這不應該是一個滾動的圖像)
在下面的截圖中,藍色區域是我的UIScrollView,黃色區域是UIView組件。使一個UIView組件向上和向下滾動
我想達到什麼是隻有黃色區域可以倒在iPhone上移和。 (我將在黃色的UIView上添加更多的UI組件,它們應該作爲一個整體移動/滾動)
我現在陷入困境,我不確定我是否處於實現它的正確方向。有人能指導我正確的方向嗎?
(我還需要改變藍色背景,這不應該是一個滾動的圖像)
嘗試把黃色的觀點在相當長的透明視圖,並放在滾動視圖的透明視圖。調整透明視圖和scrollView內容插圖的高度以調整黃色視圖滾動範圍。
但是如何將圖像作爲背景並且只有黃色區域可以上下滾動? –
將圖像設置爲滾動視圖背景或設置滾動視圖背景顏色以清除並在滾動視圖下方放置圖像視圖 –
我已經創建演示,對我來說在這裏工作的罰款是故事板XML
<!--View Controller Test-->
<scene sceneID="Mea-LA-Bdd">
<objects>
<viewController id="apb-o6-bca" customClass="ViewControllerTest" customModule="StoryBoard" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="M5h-pq-oJT"/>
<viewControllerLayoutGuide type="bottom" id="Szm-1V-GvH"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="6Fa-fa-e1T">
<rect key="frame" x="0.0" y="0.0" width="768" height="1024"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Cy8-Tt-uZI">
<rect key="frame" x="0.0" y="0.0" width="768" height="1024"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="YI6-Cd-VzM">
<rect key="frame" x="0.0" y="0.0" width="768" height="1792"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="2a3-Zk-7dR">
<rect key="frame" x="0.0" y="768" width="768" height="256"/>
<color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="height" constant="256" id="hFq-kg-mhd"/>
</constraints>
</view>
</subviews>
<color key="backgroundColor" red="0.87843137250000003" green="0.89411764709999997" blue="0.89411764709999997" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstItem="2a3-Zk-7dR" firstAttribute="centerY" secondItem="YI6-Cd-VzM" secondAttribute="centerY" id="N66-2N-D4i"/>
<constraint firstItem="2a3-Zk-7dR" firstAttribute="leading" secondItem="YI6-Cd-VzM" secondAttribute="leading" id="avT-2f-PKx"/>
<constraint firstAttribute="trailing" secondItem="2a3-Zk-7dR" secondAttribute="trailing" id="nnJ-PW-ft4"/>
</constraints>
</view>
</subviews>
<color key="backgroundColor" red="0.68627450980000004" green="0.72549019609999998" blue="0.74901960779999999" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstItem="YI6-Cd-VzM" firstAttribute="top" secondItem="Cy8-Tt-uZI" secondAttribute="top" id="C4r-zI-jfx"/>
<constraint firstAttribute="bottom" secondItem="YI6-Cd-VzM" secondAttribute="bottom" id="NDs-Z7-us0"/>
<constraint firstItem="YI6-Cd-VzM" firstAttribute="height" secondItem="Cy8-Tt-uZI" secondAttribute="height" constant="768" id="NnT-HW-g61"/>
<constraint firstItem="YI6-Cd-VzM" firstAttribute="width" secondItem="Cy8-Tt-uZI" secondAttribute="width" id="W7n-ym-257"/>
<constraint firstAttribute="trailing" secondItem="YI6-Cd-VzM" secondAttribute="trailing" id="bWQ-Fn-3rw"/>
<constraint firstItem="YI6-Cd-VzM" firstAttribute="leading" secondItem="Cy8-Tt-uZI" secondAttribute="leading" id="dTM-iV-SPc"/>
</constraints>
<edgeInsets key="layoutMargins" top="0.0" left="0.0" bottom="0.0" right="0.0"/>
</scrollView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="Cy8-Tt-uZI" firstAttribute="leading" secondItem="6Fa-fa-e1T" secondAttribute="leading" id="R2l-Qe-Ovp"/>
<constraint firstItem="Szm-1V-GvH" firstAttribute="top" secondItem="Cy8-Tt-uZI" secondAttribute="bottom" id="TTP-dE-fVr"/>
<constraint firstItem="Cy8-Tt-uZI" firstAttribute="top" secondItem="6Fa-fa-e1T" secondAttribute="top" id="xee-OO-b7e"/>
<constraint firstAttribute="trailing" secondItem="Cy8-Tt-uZI" secondAttribute="trailing" id="zAr-p0-gYR"/>
</constraints>
</view>
<connections>
<outlet property="scrollView" destination="Cy8-Tt-uZI" id="Qqw-qu-YBE"/>
<outlet property="viewToMove" destination="2a3-Zk-7dR" id="Jjc-bt-n4N"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Jhi-9S-UE4" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1317.5999999999999" y="-497.00149925037488"/>
</scene>
希望它爲你..
我認爲你應該使用的UITableView(或UICollectionView)來代替。很難控制通常的UIScrollView。你也可以設置UITableView.backgroundView = UIImageView(..) –
爲什麼你不添加平移手勢? –
看一看:https://stackoverflow.com/questions/4980534/dragging-uiview-under-finger –