如何禁用UIScrollView的水平滚动? [英] How to disable horizontal scrolling of UIScrollView?

查看:368
本文介绍了如何禁用UIScrollView的水平滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有像iPhone的Springboard一样的 UIView 。我使用 UIScrollView UIButtons 创建了它。我想在所述scrollview上禁用水平滚动。我只想垂直滚动。我如何做到这一点?

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?

推荐答案

你必须设置 contentSize UIScrollView 的属性。例如,如果您的 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的水平滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆