取消当前的UIScrollView触摸 [英] Cancel current UIScrollView touch

查看:116
本文介绍了取消当前的UIScrollView触摸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UIScrollView ,带有一些子视图,依此类推。我也是scrollView的委托并实现了 - (void)scrollViewDidScroll:(UIScrollView *)scrollView 。在我的卷轴下面还有另一个视图。

I have an UIScrollView with a few subviews and so on. I am also the scrollView's delegate and have implemented the - (void)scrollViewDidScroll:(UIScrollView *)scrollView. Underneath my scroll there is another view.

我想显示该视图,如果scrollView的 contentOffset 在x轴上低于50px,重置scrollView的 contentOffset 并取消当前的scrollView手势,以便用户在新视图出现时不会操纵其内容。

I want to show that view if the scrollView's contentOffset goes under 50px on x axis, "reset" scrollView's contentOffset and cancel the current scrollView gesture so that the user wont manipulate its content when the new view appears.

我有实现了这样的方法:

I have implemented the method like so:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (scrollView.contentOffset.x < -50)
    {
        scrollView.contentOffset = CGPointZero;
        [self showBackView];
        //here I want to cancel the current touch on the scrollview since it keeps scrolling if I drag my finger
    }
}

我试图将 userInteractionEnabled 属性设置为但只有在触摸结束后才会生效。而且我尝试过其他一些属性,但似乎都没有。

I have tried to set the userInteractionEnabled property to NO but it takes effect only after the touch has ended. And I have tried a bunch of other properties but none seems to work.

我该如何解决这个问题?

How can I fix this?

推荐答案

尝试禁用<滚动视图的code> panGestureRecognizer (然后重新启用它)。这将取消识别者的当前会话:

Try disabling the panGestureRecognizer for the scroll view (and then reenabling it). This will cancel the current session of the recogniser:

self.scrollView.panGestureRecognizer.enabled = NO;
self.scrollView.panGestureRecognizer.enabled = YES;



Swift



Swift

self.scrollView.panGestureRecognizer.isEnabled = false
self.scrollView.panGestureRecognizer.isEnabled = true

这篇关于取消当前的UIScrollView触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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