Open imzyf opened 7 years ago
// 设置双击手势
let doubleTapGesture = UITapGestureRecognizer(target: self, action: #selector(doubleClick))
doubleTapGesture.numberOfTapsRequired = 2
imageView.addGestureRecognizer(doubleTapGesture)
imageView.isUserInteractionEnabled = true
imageView.addGestureRecognizer(tapGesture)
UIPinchGestureRecognizer
UIRotationGestureRecognizer
UIPanGestureRecognizer
UISwipeGestureRecognizer swipeLeftGesture.direction = UISwipeGestureRecognizerDirection.Left //不设置是右
var longpressGesutre = UILongPressGestureRecognizer(target: self, action: "handleLongpressGesture:")
//长按时间为1秒
longpressGesutre.minimumPressDuration = 1
//允许15秒运动
longpressGesutre.allowableMovement = 15
//所需触摸1次
longpressGesutre.numberOfTouchesRequired = 1
https://stackoverflow.com/questions/38445262/pass-parameter-with-uitapgesturerecognizer
class ViewController: UIViewController {
@IBOutlet weak var label1: UILabel!
@IBOutlet weak var image: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
image.userInteractionEnabled = true;
let tappy = MyTapGesture(target: self, action: #selector(self.tapped(_:)))
image.addGestureRecognizer(tappy)
tappy.title = "val"
}
func tapped(sender : MyTapGesture) {
print(sender.title)
label1.text = sender.title
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
class MyTapGesture: UITapGestureRecognizer {
var title = String()
}
https://stackoverflow.com/questions/38445262/pass-parameter-with-uitapgesturerecognizer
class ViewController: UIViewController {
@IBOutlet weak var label1: UILabel!
@IBOutlet weak var image: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
image.userInteractionEnabled = true;
let tappy = MyTapGesture(target: self, action: #selector(self.tapped(_:)))
image.addGestureRecognizer(tappy)
tappy.title = "val"
}
func tapped(sender : MyTapGesture) {
print(sender.title)
label1.text = sender.title
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
class MyTapGesture: UITapGestureRecognizer {
var title = String()
}