UISlider和UIScrollView [英] UISlider and UIScrollView
问题描述
我有一个 UISlider
作为视图的一部分,加载到启用了分页的 UIScrollView
中。我注意到了一个意外的行为。如果用户试图快速使用滑块(即按下并移动),则激活滚动视图,导致页面切换。但是,如果按住一秒钟滑块激活,则可以调整滑块值。这种行为是不可取的。
I have a UISlider
as part of a view that is loaded into a UIScrollView
with paging enabled. I've noticed an unexpected behavior. If the user tries to use the slider quickly (i.e. press and move) it "activates" the scroll view, causing the page to switch. However, if your press and hold for a second the slider "activates" and you can then adjust the slider value. This behavior is undesirable.
加载到<$ c时使 UISlider
响应的最佳方法是什么? $ C>的UIScrollView ?我想过添加一个阻止视图,它只会占用滑块下面的触摸事件,但不确定这是否是最好的方法。
What is the best way to make the UISlider
responsive when loaded into a UIScrollView
? I've thought about adding a "blocker" view that just eats up touch events that is placed under the slider, but not sure if this is the best way to go about it.
推荐答案
让您的滚动视图检测到滑块所占区域的触摸(覆盖 hitTest:withEvent:
,您可能需要子类 UIScrollView
)。如果检测到触摸所述区域,请告诉滚动视图立即将触摸传递给滑块。
Have your scroll view detect touches over the region occupied by your slider (override hitTest:withEvent:
, you may need to subclass UIScrollView
). If a touch over said region is detected, tell your scroll view to immediately pass the touch to the slider.
这篇关于UISlider和UIScrollView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!