मेरे पास एक रचनात्मक तस्वीर है और उस पर, मैं एक छवि को एक डॉट या कुछ जैसे प्रिंट करना चाहता हूं जब उपयोगकर्ता पहली छवि (शरीर) पर टैप करता है ताकि यह इंगित किया जा सके कि यह कहां दर्द होता है।
मैंने पहले से ही UITapGestureRecognizer पर कुछ पढ़ा है, लेकिन मैं वास्तव में यह नहीं समझता कि यह कैसे काम करता है।
उत्तर:
जवाब के लिए 2 № 1इसे इस्तेमाल करे:
override func viewDidLoad() {
super.viewDidLoad()
let gestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(ViewController.handleTap))
self.imageView.addGestureRecognizer(gestureRecognizer)
}
@objc func handleTap(tap: UITapGestureRecognizer) {
let circle = UIView()
circle.center = tap.locationInView(imageView)
circle.frame.size = CGSize(width: 30, height: 30)
circle.layer.backgroundColor = UIColor.redColor().CGColor
circle.layer.cornerRadius = 15
imageView.addSubview(circle)
}