【发布时间】:2015-10-15 06:52:49
【问题描述】:
我正在实现具有 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 天开始就遇到了这个问题,但无法解决。 任何帮助都将不胜感激。 谢谢。
【问题讨论】:
标签: ios objective-c iphone uiscrollview