2011-02-18 90 views
1

如何禁用UIScrollview上的左侧滚动。这是因为用户只能向右滚动?UIScrollView水平滚动 - 禁用左侧滚动

感谢

** * UPDATE * ****

这是我现在有。我有子类的UIScrollView并重写下列方法

@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我还设置以下属性:

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

TouchesShouldBegin被调用,但touchesShouldCancelInContentView不会被调用,我不能找出原因!

谢谢

+0

我有同样的issue.didü找出原因canCancelContentTouches不会被调用即使ID canCancelContentTouches设置为YES? – prostock 2011-05-13 20:37:17

回答

1

只添加这在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; 
    } 

} 
+0

无法在iPad上使用。如果快速滚动,它将向左滚动,然后执行[aScrollView setContentOffset:CGPointMake(oldX,aScrollView.contentOffset.y)]; – ludo 2011-10-17 04:28:56