首页
学习
活动
专区
圈层
工具
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

IOS UILongPressGestureRecognizer 长按手势

代码语言:javascript
复制
 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 }
下一篇
举报
领券