- Home /
Tapping a button often scrolls outer scrollview instead of running onclick() handler.
I have a lot of buttons in a scroll view. All the buttons have onclick() actions, but I'm finding that unless I'm VERY careful and precise when tapping a button, I accidentally scroll the scrollview a very slight amount and the tap doesn't register on the button. How can I work around this? For example, it would be nice if I could take action on "finger down" event for my buttons so it won't matter whether my finger moves ever so slightly before I pick it up again.
Answer by BigScary · May 02, 2017 at 03:12 AM
I solved this by implementing the IPointerDownHandler interface. This allows me to get notified of the touch start event for my buttons without stopping that event from bubbling-up to the enclosing scroll viewer, which is important because if the event doesn't bubble up to that ancestor, then the scroll viewer won't scroll by touch.
public class LevelButton : MonoBehaviour, IPointerDownHandler
...
...
...
public void OnPointerDown(PointerEventData eventData)
{
this.OnClick();
}
Answer by csalzman · Apr 14, 2017 at 01:22 AM
Few options to try:
Your scroll rect has a Scroll Sensitivity setting. Try adjusting that and see if it helps.
Alternatively, you could try adding an
Event Trigger
component to the buttons and then "Add New Event Type" of "PointerDown". That might give you your "finger down" event.
The second option made my buttons responsive, but had the very unhappy side effect of making the scroll viewer NOT scroll on touch (unless I very precisely touch and drag the narrow scroll bar).
How can I have my buttons react to a UI event without stopping the event from propagating up to ascendant objects?
Your answer

Follow this Question
Related Questions
RPG Maker style menu with UI buttons that are selected by controller 0 Answers
Buttons shifting down on a scroller? 0 Answers
vertical layout problem using prefab buttons 1 Answer
New UI Scrollview with changing content 1 Answer
Adding a button to the content of the viewport in a scroll view through code? 0 Answers