How to steal touches from UIScrollView?

前端 未结 3 1222
情歌与酒
情歌与酒 2020-12-01 02:01

Today on my creative time I did some quite comprehensive research on how to steal touches from a UIScrollView and send them instantly to a specific subview, while maintainin

相关标签:
3条回答
  • 2020-12-01 02:30

    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

    0 讨论(0)
  • 2020-12-01 02:38

    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)
    
    0 讨论(0)
  • 2020-12-01 02:39

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

    0 讨论(0)
提交回复
热议问题