如何在 iOS 中锁定 scrollView 的水平滚动 [英] How to lock the horizontal scrolling of a scrollView in iOS

查看:40
本文介绍了如何在 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...?? ...

推荐答案

为您提供相同(改编)的答案:

在 UIScrollView 中禁用垂直滚动

好的,这里的所有答案都可以...

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屋!

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