我正在实现具有10个自定义视图的水平滚动视图,每个视图都有不同的UI。当用户向左滚动时,我正在滚动到下一个视图,在右侧滚动到上一个视图时,它工作正常,直到现在。在某些情况下,我必须限制左侧滚动并只启用右侧滚动。 在下面的方法,我得到的情况时,禁用滚动在某些情况下禁用滚动视图右侧
-(void)scrollEnabled:(BOOL)scrollEnable
{
self.scrollView.scrollEnabled = scrollEnable;
// scrollEnable comes NO at some conditions here i have to disable the right scrolling.
if(!scrollEnable)
{
// Now i am registering the pan gesture and detecting the right swiping
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(detectRightScroll:)];
[self.panView addGestureRecognizer:panGesture];
}
}
- (void) detectRightScroll:(UIPanGestureRecognizer *)gesture {
CGPoint translation = [gesture translationInView:gesture.view];
if(translation > 0) // here detecting the right scrolling and changing the scrollview content offset
{
[scrollView setContentOffset: CGPointMake(scrollView.contentOffset.x-translation, 0)];
view is scrolling but not scrolling like scrooview
}
}
就可以达到我的要求的权利,未经注册的姿态。 我从过去4天的这个问题,但无法解决。 任何帮助,可以赞赏。 谢谢。
您好anthu谢谢您的回复。只是为了澄清我正在实现水平滚动,但你更新了垂直滚动的y位置。为什么 – lazyCoder
对不起,我没注意到。但我希望你能理解我的答案。我编辑了我的答案。 – anhtu