Get CGPoint when tap gesture event happens in iwatch - apple-watch

I want to add touch points and gestures in my Apple Watch app if possible.
I read that Apple Watch doesn't provide tap or swipe gesture recognition.
Is there any way to support tap gesture events, and determine CGPoint on the Apple Watch?

watchOS 3 adds third-party support for gestures, including taps and swipes.
Your gesture recognizer action can monitor continuous touch tracking through the locationInObject() method:
Returns the point computed as the current position of the touch event.
You can find more information in the WKGestureRecognizer documentation, as well as the WatchKit Catalog sample code.

Related

Adding specific touch event to UIButton iPhone

I am trying to add a touch to UIButton.
I want it to be when I click on button, until I release the finger, it won't click on it.
I Have played with many touch events, Touch down, Touch up inside etc but none is working like that. This is a very common touch event. How can I add such a thing in iPhone UIButton?
Touch up inside will only execute when you remove your finger from the button
Touch down event will work as soon as you touch the button.
Sample Project:
https://www.dropbox.com/s/hm82u553ktyszbd/ST-16385963.zip
Touch up inside is the event you should use here. If it doesn't work, that means you haven't implemented it correctly.
Could you post your code? It sounds like you want the Touch Up Inside functionality of not firing until the finger is raised.

Using UITapGestureRecognizer rather than manually calling tapCount

I've been checking for multiple taps, whether it is 2 or 10 by simply calling tapCount on any touch:
[[touches anyObject] tapCount]==2
This simply checks for a double tap.
It works fine. I'm wondering if there is any particular reason to instead start using UITapGestureRecognizer.
It would seem that the UITapGestureRecognizer API provides wrappers around the same functionality as just inspecting touches directly, as above. Things like tapCount and the number of fingers on the screen don't require UITapGestureRecognizer.
For things like swipes, I can see the simplicity in letting UIKit handle recognizing those, as they are harder to code manually, but for a tapCount? Where's the real gain here, what am I missing?
Gesture recognizers provide for coordination in processing multiple gesture types on the same view. See the discussion of the state machine in the documentation.
If a tap is the only gesture of interest, you may not find much value, but the architecture comes in handy if you want to coordinate the recognition of taps with other gestures provided either by you or system supplied classes, such as scroll views. Gesture recognizers are given first crack at touches, so you will need to use this architecture, if you want, for example, to recognize touches in a child of a scroll view, before the scroll view processes them.
The gesture recognizers can also be set to defer recognition, so, for example, the action for a single tap is not called until a double tap has timed out.
In general, the gesture recognizer approach is a good one to adopt because it allows gestures to be managed in a consistent fashion across apps and code sources. If Apple wanted to add an assistive technology preference that allowed the user to select a longer over which a double tap would be recognized. they could do this without requiring any changes to the code of developers using standard gesture recognizers.
I should add that gesture recognizers can be added directly to your storyboard or nib, so in most cases you only need to code the target action, which could be a time saver in new code.
UITapGestureRecognizer provides a cleaner, easier to use API, but no new functionality. So for your case, no reason.

Objective-C – Options for handling touch events in Cocoa-Touch

So I believe there are numerous options for handling touch events when programming for the iDevices. A few of the options that I have come a cross are UITapGestureRecognizer and of course using UIButtons. Are there anymore options? What options are most suitable to use? Perhaps someone has a link to a guide or a tutorial that sums this up?
Cheers,
Peter
1) Target-action: UIControl (UIButton is a subclass of that) provides some built-in touch handling by adding a target and action for certain types of touch events. Example:
[myButton addTarget:self
action:#selector(buttonTapped:)
forControlEvents:UIControlEventTouchUpInside];
2) Overriding the UIView methods touchesBegan:withEvent:, touchesMoved:withEvent:, touchesEnded:withEvent: and touchesCancelled:withEvent: – Provides very fine-grained control but can be difficult to use for complex multitouch handling.
3) Gesture recognizers (since iOS 3.2): Recognition of multitouch (or single touch) gestures that are usually comprised of multiple touch events. The built-in gesture recognizers provide support for recognizing taps, pinches, rotation gestures, swipes, panning and long presses. It's also possible to create custom gesture recognizers for more complex gestures.
All the gesture recognizer subclasses are customizable to a certain degree, e.g. you can specify a minimum number of taps and touches for a UITapGestureRecognizer.
Generally, gesture recognizers can both provide discrete events (like a tap) and continuous events (like a rotation that changes its angle over time).
The best resource by far is the WWDC 2011 Video on Multi-Touch (requires a developer account):
http://developer.apple.com/itunes/?destination=adc.apple.com.8270634034.08270634040.8367260921?i=1527940296
This goes over using both gesture recognizers as well as custom touch handling.
I'd use the UIGestureRecognizers for specific gestures (pan, pinch etc) or the touch handling methods which are inherited from UIResponder class (in UIViewController for instance)....
– touchesBegan:withEvent:
– touchesMoved:withEvent:
– touchesEnded:withEvent:
– touchesCancelled:withEvent:
There are a LOT of resources on handling touches in Cocoa-touch. Just google it or even search here on this site for specifics.

how to stop user use more than two fingers to touch

in my app, I want users only use one finger to touch the ipad, it means, when you touch the screen, others touches won't respond events......
any helps?
try disabling multitouch throug IB or through code.
keep a track of count of touch, and then implement it accordingly.

Touch up outside location from UI Button

I am trying to write a method that receives the coordinates of a ending touch event when a user touches a button and then drags off off the button. Is the touch coordinate information available if the button is passed into the method as the sender? Any suggestions are welcome.
The touch coordinates information is not available form the sender. But your action's selector can take the form
-(IBAction)dragOutside:(id)sender withEvent:(UIEvent*)event;
and the event does contain the coordinates and other things.
You will not get the coordinate information in the sender function of UIButton. you could use to detect touch events by implementing the UIResponder functions.
– touchesBegan:withEvent:
– touchesEnded:withEvent:
– touchesCancelled:withEvent:
- touchesEnded:withEvent:
Have a look SO post
How do you recognize drag gestures