Author Topic: UIButton - sending event on touch down, not touch up  (Read 2542 times)

Biggix

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 33
    • View Profile
UIButton - sending event on touch down, not touch up
« on: December 19, 2014, 07:34:17 PM »
Hi,

I'm having a bunch of UIButtons. They work fine, however on iOS device they send info to script mentioned in the onClick field, when the user's finger is LIFTED from the button.

I really need the action to happen, just when the user touches the UIbutton, without waiting when he will lift the finger.

How do I accomplish this?

Thanks!

Biggix

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 33
    • View Profile
Re: UIButton - sending event on touch down, not touch up
« Reply #1 on: December 21, 2014, 11:11:27 PM »
Hey I'm really waiting for any support regarding this issue. It is driving me crazy! Having events upon touch up is absolutely unacceptable behavior. I need them to happen on touch down!  :-[

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIButton - sending event on touch down, not touch up
« Reply #2 on: December 22, 2014, 10:21:18 AM »
UICamera has a touch threshold. it's 40 pixels by default. Raise it up higher, and make sure your button colliders are big enough so that your finger doesn't slide off them.

If you want just the touch down event, then that's OnPress(true). OnClick is not the right even for it.

Biggix

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 33
    • View Profile
Re: UIButton - sending event on touch down, not touch up
« Reply #3 on: May 15, 2016, 11:25:15 AM »
Hi,

I'm still struggling with it.

In UIButton.cs, if I change "OnClick()" function with "OnPress()", it works but it sends out two events: one on touch down, and a second one on touch up.

I don't want anything to happen on touch up, just the touch down! How do I do it?

Also, is there an easy way to implement the long tap support into UIButton?

Thanks!


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIButton - sending event on touch down, not touch up
« Reply #4 on: May 18, 2016, 04:44:16 AM »
  1. void OnPress (bool isPressed)
  2. {
  3.     if (isPressed) Invoke("LongPress", 1f);
  4.     else CancelInvoke("LongPress");
  5. }
  6.  
  7. void LongPress ()
  8. {
  9.     Debug.Log("Long press on " + name);
  10. }