IOS UILongPressGestureRecognizer 长按手势

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

5 self.imageView = UIImageView(frame:rect)
6
7 let image = UIImage(named:“lock”)
8 imageView.image = image
9
10 imageView.isUserInteractionEnabled = true
11 self.view.addSubview(self.imageView)
12
13 let guesture = UILongPressGestureRecognizer(target:
self, action:#selector(ViewController.longPress(:)))
14 guesture.minimumPressDuration = 1.0
15 guesture.allowableMovement = 20.0
16 imageView.addGestureRecognizer(guesture)
17 }
18 func longPress(
gusture:
UILongPressGestureRecognizer)
19 {
20 if(gusture.state == UIGestureRecognizerState.began)
21 {
22 let image = UIImage(named:“unlock”)
23 imageView.image = image
24 }
25 }

猜你喜欢

转载自blog.csdn.net/weixin_34050005/article/details/90866465