我有以下代码,我的长按不按预期方式工作.任何人都可以弄清楚它为什么不起作用?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let longPressRecognizer = UILongPressGestureRecognizer(target: self, action: "myButton:")
longPressRecognizer.minimumPressDuration = 0.5
myButton.addGestureRecognizer(longPressRecognizer)
}
@IBOutlet weak var myButton: UIButton!
@IBAction func myButton(longPress: UILongPressGestureRecognizer) {
if longPress.state != .Began {
presentAlertController()
return
}
}
Run Code Online (Sandbox Code Playgroud)
当我按住按钮时出现此错误
2016-01-09 00:41:28.785 longPressTest[1870:551106] Warning: Attempt to present <UIAlertController: 0x144d6a500> on <longPressTest.ViewController: 0x144e3a450> which is already presenting <UIAlertController: 0x144e59d80>
2016-01-09 00:41:28.903 longPressTest[1870:551106] Attempting to load the view of a view …Run Code Online (Sandbox Code Playgroud) 我有一个带6个按钮的屏幕.所有按钮都连接到一个IBAction.它们被标记,我使用switch语句来确定哪个被点击.
如何为每个按钮添加Long和Tap手势?例如,当我点击按钮1时,它知道它是一个长手势还是一个轻敲手势?
因此,如果我点击按钮会做出不同的事情,那么当我长按时.
谢谢.
@IBAction func playPauseAudioButton(sender: UIButton) {
switch sender.tag {
case 1:
//Tap Gesture
//Long Gesture
//I need this for every button
print("1")
case 2:
print("2")
case 3:
print("3")
case 4:
case 5:
print("5")
case 6:
print("6")
default:
print("Default")
}
}
Run Code Online (Sandbox Code Playgroud)