問題描述
我有一個(gè) UIView
像 iPhone 的 Springboard.我使用 UIScrollView
和 UIButtons
創(chuàng)建了它.我想在所述滾動(dòng)視圖上禁用水平滾動(dòng).我只想要垂直滾動(dòng).我該如何做到這一點(diǎn)?
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?
推薦答案
你必須設(shè)置 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
只會(huì)垂直滾動(dòng),因?yàn)樗呀?jīng)可以水平顯示所有內(nèi)容.
The UIScrollView
will then only scroll vertically, because it can already display everything horizontally.
這篇關(guān)于如何禁用 UIScrollView 的水平滾動(dòng)?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!