swift 3 如何让UIAlertView出现在手指离开之前?
How to make a UIAlertView appears before the finger lift off in swift 3?
我有一个 UITableView
,我想制作一个 UIAlertView
出现在 UILongPressGestureRecognizer
上。
它现在运行良好,我必须将手指从屏幕上移开才能看到它出现。
有没有办法让它在0.5秒后(例如)出现,即使手指还在屏幕上?
用属性的UILongPressGestureRecognizer
?
编辑:
class Settings: UIViewController , UITableViewDataSource, UITableViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let longPress = UILongPressGestureRecognizer(target: self, action: #selector(Settings.deleteItem))
self.tableView.addGestureRecognizer(longPress)
}
func deleteItem(longPress:UIGestureRecognizer) {
if longPress.state == UIGestureRecognizerState.ended {
let pressedLocation = longPress.location(in: self.tableView)
if let pressedIndexPath = tableView.indexPathForRow(at: pressedLocation) { //Give the row where it's touched
RowSelected = (actionList?[pressedIndexPath[1]])!
print(RowSelected)
longtouched = pressedIndexPath[1]
let alert = UIAlertController(title: "What do you want to do?", message: "Select the action you want to do.", preferredStyle: UIAlertControllerStyle.alert)
let Cancel = UIAlertAction(title: "Cancel", style: .default) { actio in
print("Canceled")
}
let Delete = UIAlertAction(title: "Delete", style: .default) { actio in
//DOING MY STUFF
}
let Modify = UIAlertAction(title: "Modify", style: .default) { actio in
UserDefaults.standard.set(self.longtouched, forKey: "modify")
self.performSegue(withIdentifier: "ToModify", sender: self)
}
alert.addAction(Modify)
alert.addAction(Delete)
alert.addAction(Cancel)
self.present(alert, animated: true, completion: nil)
}
}
}
其实我已经亲眼看到了这个问题。
如果有人遇到同样的问题,只需将 if longPress.state == UIGestureRecognizerState.ended
更改为 if longPress.state == UIGestureRecognizerState.began
它会成功的。
我有一个 UITableView
,我想制作一个 UIAlertView
出现在 UILongPressGestureRecognizer
上。
它现在运行良好,我必须将手指从屏幕上移开才能看到它出现。
有没有办法让它在0.5秒后(例如)出现,即使手指还在屏幕上?
用属性的UILongPressGestureRecognizer
?
编辑:
class Settings: UIViewController , UITableViewDataSource, UITableViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let longPress = UILongPressGestureRecognizer(target: self, action: #selector(Settings.deleteItem))
self.tableView.addGestureRecognizer(longPress)
}
func deleteItem(longPress:UIGestureRecognizer) {
if longPress.state == UIGestureRecognizerState.ended {
let pressedLocation = longPress.location(in: self.tableView)
if let pressedIndexPath = tableView.indexPathForRow(at: pressedLocation) { //Give the row where it's touched
RowSelected = (actionList?[pressedIndexPath[1]])!
print(RowSelected)
longtouched = pressedIndexPath[1]
let alert = UIAlertController(title: "What do you want to do?", message: "Select the action you want to do.", preferredStyle: UIAlertControllerStyle.alert)
let Cancel = UIAlertAction(title: "Cancel", style: .default) { actio in
print("Canceled")
}
let Delete = UIAlertAction(title: "Delete", style: .default) { actio in
//DOING MY STUFF
}
let Modify = UIAlertAction(title: "Modify", style: .default) { actio in
UserDefaults.standard.set(self.longtouched, forKey: "modify")
self.performSegue(withIdentifier: "ToModify", sender: self)
}
alert.addAction(Modify)
alert.addAction(Delete)
alert.addAction(Cancel)
self.present(alert, animated: true, completion: nil)
}
}
}
其实我已经亲眼看到了这个问题。
如果有人遇到同样的问题,只需将 if longPress.state == UIGestureRecognizerState.ended
更改为 if longPress.state == UIGestureRecognizerState.began
它会成功的。