0

I am trying to implement a CustomKeyboard as an application extension to my iOS device. What I need is the exact click location on buttons. Some users may click a little to the edge, whereas some click right in the middle of the buttons. Is there a way do achieve that?

I am trying to write it in Swift but objective-c is ok too

Getting the coordinates from the location I touch the touchscreen mentions a similar thing, but I need the coordinates from the button event, not some image. Steve's link seems to be the answer tho. I will try that one. Thanks I

Community
  • 1
  • 1
Salih Ahi
  • 1
  • 5

1 Answers1

2

One of the optional method signatures for an IBAction takes a UIEvent:

- (IBAction)doSomething:(id)sender forEvent:(UIEvent*)event;

Or in Swift:

@IBAction func doSomething(sender: UIButton, forEvent event: UIEvent)

For touch events like a TouchUpInside event, the event will be a Touch event. A touch event will include one or more UITouch objects. You can get the touch's coordinates in the target view from the UITouch object.

Duncan C
  • 128,072
  • 22
  • 173
  • 272