UIScrollView水平滚动-禁用向左滚动 [英] UIScrollView Horizontal scrolling - Disable left scroll
问题描述
如何禁用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屋!