Skip to content

Latest commit

 

History

History
23 lines (17 loc) · 599 Bytes

File metadata and controls

23 lines (17 loc) · 599 Bytes

UITapGestureRecognizer

import UIKit

class ViewController: UIViewController {

    @IBOutlet var myUIImageView: UIImageView!

    override func viewDidLoad() {
        super.viewDidLoad()

        let singleTap = UITapGestureRecognizer(target: self, action: #selector(myUIImageViewTapped(_: )))
        self.myUIImageView.addGestureRecognizer(singleTap)
    }

    @objc func myUIImageViewTapped(_ recognizer: UITapGestureRecognizer) {
        if recognizer.state == UIGestureRecognizer.State.ended {
            print("myUIImageView has been tapped by the user.")
        }
    }
}