如何在iOS中锁定scrollView的水平滚动 [英] How to lock the horizontal scrolling of a scrollView in iOS
问题描述
我有一个scrollView。我希望它只在一个方向滚动(垂直)。有没有办法可以锁定水平滚动... ?? ...
i have a scrollView. i want it to scroll only in one direction(VERTICAL). Is there a way in which i can lock the horizontal scrolling...?? ...
推荐答案
相同(改编)的答案,如:
对,这里的所有答案都可以......
right, all answers here are ok...
但如果出于某种奇怪的原因你的contentSize应该在两个维度上都高于 UIScrollView
,您可以禁用实现 UIScrollView
协议方法的水平滚动 - (void)scrollViewDidScroll:(UIScrollView *)aScrollView
but if for some strange reason your contentSize should be higher than the UIScrollView
in both dimensions, you can disable the horizontal scrolling implementing the UIScrollView
protocol method -(void)scrollViewDidScroll:(UIScrollView *)aScrollView
只需在 UIViewController中添加
float oldX; // here or better in .h interface
- (void)scrollViewDidScroll:(UIScrollView *)aScrollView
{
[aScrollView setContentOffset: CGPointMake(oldX, aScrollView.contentOffset.y)];
// or if you are sure you wanna it always on left:
// [aScrollView setContentOffset: CGPointMake(0, aScrollView.contentOffset.y)];
}
这只是用户滚动时调用的方法UIScrollView
,这样做会强制它的内容始终相同。 x
it's just the method called when the user scroll your UIScrollView
, and doing so you force the content of it to have always the same .x
这篇关于如何在iOS中锁定scrollView的水平滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!