Touch on UISlider prevents scrolling of UIScrollView

前端 未结 5 1589
日久生厌
日久生厌 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:01

    Your question confused me a bit. You are saying a vertical slider - but dragging left and right?

    If you wish to scroll the scrollview when dragging the UISlider, the proper way to do so is

    [mySlider addTarget:self action:@selector(sliderMoved:) forControlEvents:UIControlEventValueChanged];
    

    and

    - (void) sliderMoved:(UISlider*) slider {
        myScrollView.contentOffset.x = slider.value * (myScrollView.contentSize.width - myScrollView.bounds.size.width);
    }
    

    Hope this is what you want.

提交回复
热议问题