Search code examples
iosuiscrollviewuitouch

iOS do not forward touches to views below


In my app I have UIScrollView which has many UITableViews. In cells of this table there is UISlider. How I can disable touch forwarding if user make scroll gesture on table view? Now if user make scroll gesture near slider (but not on it) the touch event gets forwarder to scroll view.


Solution

  • You can subclass UIScrollView and add this method to the new class

    - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    
        UIView *result = [super hitTest:point withEvent:event] ;
        self.scrollEnabled = ![result isKindOfClass:[UISlider class]] ;
        return result ;
    
    }