我的用户界面上有多个按钮,我想根据不同类型的点击执行不同的功能,
- 单击
- 双击
- 长按
单击一次对我来说很容易,一个连接了所有四个按钮的 IBAction,但是对于其他类型的点击,我被卡住了,
我知道我需要使用点击手势识别器,但我无法将其设置为多个 UIButtons,
这是我想做的例子
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var Label: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func ButtonSingleTap(sender:UIButton!) {
let ButtonNumber: String = String(sender.tag)
Label.text = "Button " + ButtonNumber + " is Single Tapped"
}
func ButtonDoubleTap(sender:UIButton!) {
let ButtonNumber: String = String(sender.tag)
Label.text = "Button " + ButtonNumber + " is Double Tapped"
}
func ButtonLongTap(sender:UIButton!) {
let ButtonNumber: String = String(sender.tag)
Label.text = "Button " + ButtonNumber + " is Long Pressed"
}
}