Is it possible to remove the delay of UIButton's highlighted state inside a UIScrollView?

前端 未结 1 488
暖寄归人
暖寄归人 2021-02-01 16:14

I have noticed a slight delay on the highlighted state of a UIButton when touched down if it is inside a UIScrollView (or a table view). Otherwise, the highlighted state is pret

相关标签:
1条回答
  • 2021-02-01 16:46

    Indeed, it's a design choice. It needs this small time to differentiate a scroll (panGesture) from a tap. If you eliminate this delay, then the user won't be able to scroll if he places the finger on top of the button, which is not good user experience.

    Because a scroll view has no scroll bars, it must know whether a touch signals an intent to scroll versus an intent to track a subview in the content. To make this determination, it temporarily intercepts a touch-down event by starting a timer and, before the timer fires, seeing if the touching finger makes any movement. If the timer fires without a significant change in position, the scroll view sends tracking events to the touched subview of the content view.

    from the UIScrollView Documentation

    I wouldn't recommend disabling the delay, but if you insist, you can set it in interface builder (select the Scroll View, and on the right panel, right under "Bounces Zoom"), or using this code:

    scrollView.delaysContentTouches = false
    
    0 讨论(0)
提交回复
热议问题