Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by karl_ · Aug 30, 2010 at 08:38 PM · iosinputtouchtapiphoneinput

Detect a tap versus standing touch on iPhone?

So far I've tried to run a for loop while detecting a touch, and call it a tap if under X loops and a touch for over. However, that did not work nearly as well as expected. Is there a built in way to detect a tap versus a sliding touch?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Bampf · Aug 31, 2010 at 02:45 AM

In my app I assume it's a tap unless the phase becomes Moved. So when the phase is Ended, if it never became Moved, then it was a tap. This works well for (say) a scrolling list that they can either drag, or tap on one of the lines.

You could add a time limit to the above logic by adding up all the deltaTime values after the Began phase. Once the time limit is exceeded you'd treat it the same as if they moved their finger.

Remember to reset your timer and other variables when the phases Ended or Cancelled occur.

An alternative I haven't tried is using iPhoneTouch.tapCount. By reading it you might be able to detect single-taps (when the count goes to 1, get the position of the tap.) The documentation is vague on the behavior but it sounds like it has some logic for deciding when the user tapped one or more times.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by jtbentley · Aug 30, 2010 at 11:54 PM

A touch has several phases (TouchPhase)...

Began, Moved, Stationary, Ended, Canceled.

if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) doStuff();

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by geo · Jan 18, 2011 at 02:12 PM

Unity does most of the work for you here, you need to look at the tapCount of the "Ended" touch (touch.phase = TouchPhase.Ended).

In my testing, I found that if the user pressed and released on the same spot (in under ~1 second) then the tapCount of the "Ended" touch is 1. If they have dragged at all in between pressing and releasing, the tapCount is always 0. Also if they press but hold on the spot for over a second and then release, the tapCount is also 0.

If the maximum tap duration of around 1 second is too long, you'd probably need write your own version of this functionality.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Touch joystick tutorials ? 0 Answers

Best way to get to get touch inputs? 1 Answer

How to fix this problem? ios touch screen? 1 Answer

touch game objects on ios 1 Answer

Way to detect and get last/latest TOUCH 5 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges