Touch on UISlider prevents scrolling of UIScrollView

前端 未结 5 1604
日久生厌
日久生厌 2021-02-20 10:28

I have a (vertical) UISlider inside a UIScrollview. I\'d like to be able to change the value of the slider, and, without lifting my finger, scroll the scrollview left or right.

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-20 11:10

    Have you tried subclassing UIScrollView and implementing - (BOOL)touchesShouldCancelInContentView:(UIView *)view? According to the Apple documentation:

    // called before scrolling begins if touches have already been delivered to a subview of the scroll view. if it returns NO the touches will continue to be delivered to the subview and scrolling will not occur
    // not called if canCancelContentTouches is NO. default returns YES if view isn't a UIControl
    

    If you simply return NO if the view is your UISlider, this may do what you want, assuming your UIScrollView only scrolls horizontally. If this doesn't work, you likely will have to do custom touch handling (ie. overriding touchesBegan:withEvent:, touchesChanged:withEvent:, etc.) for both your UIScrollView and your UISlider.

提交回复
热议问题