問題描述
我有一個 UIView
像 iPhone 的 Springboard.我使用 UIScrollView
和 UIButtons
創建了它.我想在所述滾動視圖上禁用水平滾動.我只想要垂直滾動.我該如何做到這一點?
I have a UIView
like iPhone's Springboard. I have created it using a UIScrollView
and UIButtons
. I want to disable horizontal scrolling on said scrollview. I want only vertical scrolling. How do I accomplish this?
推薦答案
你必須設置 UIScrollView
的 contentSize
屬性.例如,如果你的 UIScrollView
是 320 像素寬(屏幕的寬度),那么你可以這樣做:
You have to set the contentSize
property of the UIScrollView
. For example, if your UIScrollView
is 320 pixels wide (the width of the screen), then you could do this:
CGSize scrollableSize = CGSizeMake(320, myScrollableHeight);
[myScrollView setContentSize:scrollableSize];
UIScrollView
只會垂直滾動,因為它已經可以水平顯示所有內容.
The UIScrollView
will then only scroll vertically, because it can already display everything horizontally.
這篇關于如何禁用 UIScrollView 的水平滾動?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!