How to steal touches from UIScrollView?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 06:48:38
Erik B

Sometimes you have to ask the question before you can find the answer. Dan Ray had a similar problem and solved it with a very different solution.

- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
    UIView* result = [super hitTest:point withEvent:event];

    if ([result.superview isKindOfClass:[UIPickerView class]])
    {
        self.scrollEnabled = NO;
    }
    else 
    {
        self.scrollEnabled = YES;    
    }
    return result;
}

I've tested the code and it works fine for me as well. However, this is not really stealing touches from the scroll view, so if anyone knows how to actually steal touches that would be great.

Source: UIPickerView inside UITableView.tableFooterView doesn't receive drag touches

A bit late, but I found this solution: http://www.cocoanetics.com/2010/06/hacking-uiscrollview-gesture-recognizers/ Works for me

I'm also late to the party, but for newcomers, if you're just looking to flat out ignore swipes on the scroll view, what worked for me was to add a pan gesture recognizer to the view I want ignoring the swipes, like this:

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