UIScrollView水平滚动-禁用向左滚动 [英] UIScrollView Horizontal scrolling - Disable left scroll

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

问题描述

如何禁用UIScrollview上的向左滚动.这样用户只能向右滚动吗?

How can I disable scrolling left on a UIScrollview. This is so users can only scroll right?

谢谢

** * 更新 * ****

*** UPDATE *****

这就是我现在所拥有的.我继承了UIScrollView的子类,并覆盖了以下方法

This is what I have now. I have subclassed UIScrollView and overwritten the following methods

@implementation TouchScrollView

- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view {
    NSLog(@"touchesShouldBegin: I was touched!");
    return YES;
}

- (BOOL)touchesShouldCancelInContentView:(UIView *)view {
    NSLog(@"touchesShouldCancelInContentView: I was touched!");
    return NO;
}

在我的viewController中,我还设置了以下属性:

In my viewController I have also set the following attributes:

scrollView.delaysContentTouches = NO;
scrollView.canCancelContentTouches = YES;

正在调用TouchesShouldBegin但没有调用touchesShouldCancelInContentView,我不知道为什么!

TouchesShouldBegin is being called but touchesShouldCancelInContentView is not being called and I cant figure out why!!

谢谢

推荐答案

只需将其添加到您的UIViewController UIScrollViewDelegate

just add this in your UIViewController UIScrollViewDelegate

float oldX; // here or better in .h interface

- (void)scrollViewDidScroll:(UIScrollView *)aScrollView
{
    if (scrollView.contentOffset.x < oldX) {
        [aScrollView setContentOffset: CGPointMake(oldX, aScrollView.contentOffset.y)];
    } else {
        oldX = aScrollView.contentOffset.x;
    }

}

这篇关于UIScrollView水平滚动-禁用向左滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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