Touch up outside location from UI Button - iphone

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

Related

Get CGPoint when tap gesture event happens in iwatch

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.

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.

UIControlEventTouchDragEnter doesn't seem to work for catching a tap that slides into a control

I wanted to allow for a method to get called, if a finger was dragged from outside into the bounds of a control. I thought UIControlEventTouchDragEnter would do it, but it doesn't seem to. Does anyone know if there is a way to trigger an action based on a tap sliding into a control?
This is what I was trying, but got no calls to my -fingerSlidIn:
[aButton addTarget:self action:#selector(fingerSlidIn:withEvent: ) forControlEvents: UIControlEventTouchDragEnter];
Thanks!
This is by design. All events belonging to a continuous touch (from touch down until touch up) go to the view that received the first touch down event. So you will never receive a UIControlEventTouchDragEnter unless the user moved the finger away from the control and back.
To do what you want, you would have to capture the touches on the control's container view and determine manually when the touch coordinates enter your control's frame rect (possibly by calling pointInside:withEvent: for every touch you receive).

Signature Panel

My requirements are I need a panel where user can make signature. The concept is like when user touches the screen and move the pointer, it should be marked with continuous line.
Please gimme some idea how to implement this??
Subclass UIView and override the various UIResponder methods dealing with touch. Especially pay attention to touchesMoved:withEvent: - this is the method where you can get data about the previous/current points of the touch, and potentially add them to a set of points the touch has moved through. You can also override drawRect: in your custom UIView to draw a curve through all the points the touch has passed.
More info:
UIResponder reference
UIView reference

Cocoa Touch behavior for events

I have been over the iPhone Programming Guide several times regarding the behavior of when the event methods are called in an app.
From what the guide says:
touchesBegan is called when a finger first touches the screen.
touchesMoved is called when a finger on the screen moves.
touchesEnded is called when a finger lifts off the screen.
The issue becomes a little clouded with multiple fingers are involved:
Even with the Multi-touch Interaction flag set to NO, the app continues to call the touchesBegan method of a view that is currently tracking another touch. This seems counter intuitive to me.
Is this the correct behavior? I would think that a new UITouch (even added to the current event being tracked) would not trigger the touchesBegan method.
Of note, I set this flag in IB as well as programatically to make sure I wasn't missing something.
Thanks,
Corey
Yes I believe it is correct behavior. You can track the location of each touch event so I think you just need to structure your logic such that you handle:
UITouch *touch = [[allTouches allObjects] objectAtIndex:0];
to get the first touch, and objectAtIndex:1 for the second. I think it goes up to four or five (not sure, please see the docs).
Good luck!
I figured out my problem, but first to clarify proper functionality of multiple touches:
If your view's multipleTouchEnabled flag is set to NO, the touchesBegan method of that view should NOT fire if a second touch is applied to a screen.
With that, the solution to my problem:
My view contains several subviews. The view is responsible for handling touches for itself AND the subviews.
When my code was not functioning properly, I had the subview's userInteractionEnabled = YES. This meant that when a subview was touched, it would forward the touch to the superview, REGARDLESS of whether the superview was tracking another touch.
In other words, although UIApplication respects the multiTouchEnabled flag of a view, other views in the responder chain do not.