我有一个 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模板网!
如何继承 UIScrollView 并使委托属性私有How to subclass UIScrollView and make the delegate property private(如何继承 UIScrollView 并使委托属性私有)
Swift - 如何从照片库中获取最后拍摄的 3 张照片Swift - how to get last taken 3 photos from photo library?(Swift - 如何从照片库中获取最后拍摄的 3 张照片?)
以编程方式设置 contentOffset 触发 scrollViewDidScrolSetting contentOffset programmatically triggers scrollViewDidScroll(以编程方式设置 contentOffset 触发 scrollViewDidScroll)
使用 pagingEnabled 的 UIScrollView 中页面之间的照片应Photos app-like gap between pages in UIScrollView with pagingEnabled(使用 pagingEnabled 的 UIScrollView 中页面之间的照片应用程序式间隙
为什么 UIScrollView 在 ios 6 和 ios 7 中从顶部留下空why UIScrollView is leaving space from top in ios 6 and ios 7(为什么 UIScrollView 在 ios 6 和 ios 7 中从顶部留下空间)
UIScrollView 在滚动时暂停 NSTimerUIScrollView pauses NSTimer while scrolling(UIScrollView 在滚动时暂停 NSTimer)