override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let rect = CGRect(x: 32, y: 80, width: 256, height: 256)
let imageView = UIImageView(frame: rect)
let image = UIImage(named: "05")
imageView.image = image
imageView.isUserInteractionEnabled = true
self.view.addSubview(imageView)
let guesture = UITapGestureRecognizer(target: self, action: #selector(ViewController.doubleTap))//创建一个手势对象,用于检测手势
guesture.numberOfTapsRequired = 2//设置次数2,模拟双击
guesture.numberOfTouchesRequired = 1//设置手势为单次双击事件
imageView.addGestureRecognizer(guesture)
}
//创建一个方法,用于接收手势事件
@objc func doubleTap() {
let alertView = UIAlertController(title: "Information", message: "Double Tap", preferredStyle: UIAlertControllerStyle.alert)//收到手势事件后,弹出一个提示窗
let OKAction = UIAlertAction(title: "OK", style: .default, handler: {_ in})//为提示窗创建一个“确定”按钮,用于点击关闭窗口
alertView.addAction(OKAction)//将按钮添加到提示窗
self.present(alertView, animated: true, completion: nil)//在当前视图控制器中,展示提示窗口
}