IOS UITapGestureRecognizer点击手势

var imageView:UIImageView!
2 override func viewDidLoad() {
3 super.viewDidLoad()
4 // Do any additional setup after loading the view,
typically from a nib.
5 let rect = CGRect(x:0, y:80, width:320, height:

6 self.imageView = UIImageView(frame:rect)
7
8 let image = UIImage(named:“lock”)
9 imageView.image = image
10
11 imageView.isUserInteractionEnabled = true
12 self.view.addSubview(self.imageView)
13
14 let guesture = UITapGestureRecognizer (target:self,action:#selector(ViewController.singleTap))
15 imageView.addGestureRecognizer(guesture)
16 }
17 func singleTap()
18 {
19 let image = UIImage(named:“unlock”)
20 imageView.image = image
21 }

你可能感兴趣的:(IOS UITapGestureRecognizer点击手势)