I have a UIButton stretched to the size of the view (covers the view/screen).
I have set a Touchdown action and I need in this action to find out what is the location of the tap/press on the button (get x and y coordinates).
Is it possible?
Create the action function with sender and event params. Then you can get the touch location on the button.
@IBAction func buttonAction(sender: AnyObject, event: UIEvent) {
// downcast sender as a UIView
let buttonView = sender as UIView;
// get any touch on the buttonView
if let touch = event.touchesForView(buttonView)?.anyObject() as? UITouch {
// print the touch location on the button
println(touch.locationInView(buttonView))
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With