How do I get the coordinates for finger tapping in UIView?

前端 未结 5 716
-上瘾入骨i
-上瘾入骨i 2020-12-19 05:31

How do I get the coordinates for finger tapping in UIView? (I would prefer not to use a big array of buttons)

Thank you

5条回答
  •  有刺的猬
    2020-12-19 06:03

    Swift 3 answer

    let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.tapAction(_:)))
    yourView.addGestureRecognizer(tapGesture)
    
    
    func tapAction(_ sender: UITapGestureRecognizer) {
    
          let point = sender.location(in: yourView)
    
    
    }
    

提交回复
热议问题