当我向UIScrollView添加A UIPangesturerecognizer时,滚动被禁用 [英] Scrolling is disabled when i add A UIPangesturerecognizer to UIScrollView

查看:563
本文介绍了当我向UIScrollView添加A UIPangesturerecognizer时,滚动被禁用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个滚动视图,我想让它在平移完成时消失。
它工作正常并且在平移时,scrollview消失但问题是现在我无法滚动内容。

I have a scroll view and i want to make it disappear whenever a pan is done. It works fine and on panning , scrollview disappear but the problem is now i cant scroll the contents.

[UIView animateWithDuration:0.2
                      delay:0.2
                    options: UIViewAnimationCurveLinear
                 animations:^{
                     slideView.frame=CGRectMake(268, 0, 500, 950);
                     curtain.frame=CGRectMake(0, 0, 268, 950);
                     curtain.backgroundColor=[[UIColor alloc]initWithRed:0 green:0 blue:0 alpha:0.6];
                     [self.view addSubview:slideView];
                    [self.view addSubview:curtain];

                 } 
                 completion:^(BOOL finished){
                     NSLog(@"Done!");
                 }];

这就是我如何让我的uiscrollview出现(slideview是scrollview)。然后我添加pangesturerecognizer.All工作正常但滚动被禁用。 (panImage再次隐藏了我的幻灯片。)如何进行滚动工作。

this is how i how i make my uiscrollview to appear (slideview is scrollview).And then I add a pangesturerecognizer.All works fine but scrolling is disabled. (panImage again hides my slideview.)how to make scrolling works .??

[slideView addGestureRecognizer:panImage];


推荐答案

UIScrollView 有自己的平移手势识别器,可以控制滚动。通过添加另一个平移手势识别器,您可以阻止滚动视图自己的平移手势识别器工作。

UIScrollView has its own pan gesture recognizer, which controls scrolling. By adding another pan gesture recognizer, you are preventing the scroll view's own pan gesture recognizer from working.

有很多方法可以解决这个问题,但它会是如果您可以解释系统在用户尝试关闭滚动视图时以及何时尝试滚动时,系统应该如何解释,因为您需要平移手势来执行这两项操作。

There are a number of ways to deal with this, but it would be helpful if you could explain how the system is supposed to know when the user is trying to dismiss the scroll view, and when he is trying to scroll, since you want a pan gesture to do both.

例如,您可以设置两个手势识别器的代理,以允许识别器同时操作(通过覆盖 gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:方法)。您可以使每个手势识别器需要不同数量的触摸(通过设置 minimumNumberOfTouches maximumNumberOfTouches 属性)。您可以使用 UISwipeGestureRecognizer 来识别关闭手势。您可以通过覆盖滚动视图委托的 scrollViewDidScroll:方法来检测用户何时尝试滚动滚动视图的左边缘。

For example, you could set the delegates of both gesture recognizers to allow the recognizers to operate simultaneously (by overriding the gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: method). You could make each gesture recognizer require a different number of touches (by setting the minimumNumberOfTouches and maximumNumberOfTouches properties). You could use a UISwipeGestureRecognizer to recognize the dismiss gesture. You could detect when the user tries to scroll past the left edge of the scroll view by overriding the scrollViewDidScroll: method of the scroll view's delegate.

这篇关于当我向UIScrollView添加A UIPangesturerecognizer时,滚动被禁用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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