How do I get the tap coordinates on a custom UIButton?

前端 未结 3 650
[愿得一人]
[愿得一人] 2020-12-16 19:09

I\'m using XCode 4.4 developing for iOS 5 on an iPad and am using the Storyboard layout when creating my custom button.

I have the touch event correctly working and

3条回答
  •  再見小時候
    2020-12-16 20:00

    Incase of Swift 3.0 the accepted answer works same except syntax will be changed as follows:

    Swift 3.0:

     @IBAction func buyTap(_ sender: Any, forEvent event: UIEvent) {
         let myButton = sender as! UIButton
         let touches = event.touches(for: myButton)
         let touch = touches?.first
         let touchPoint = touch?.location(in: myButton)
         print("touchPoint\(touchPoint)")
      }
    

提交回复
热议问题