Cancel current UIScrollView touch

你说的曾经没有我的故事 提交于 2019-11-30 15:08:29

问题


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.

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
    }
}

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?


回答1:


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

ObjC

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

Swift

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


来源:https://stackoverflow.com/questions/18497192/cancel-current-uiscrollview-touch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!