如何使UIAlertView在手指快速抬起之前出现3?
问题描述:
我有一个UITableView
,我想使一个UIAlertView
出现在UILongPressGestureRecognizer
上。如何使UIAlertView在手指快速抬起之前出现3?
现在效果很好,是我必须抬起屏幕的手指才能看到它出现。
即使手指仍然在屏幕上,是否有一种方法可以让它在0.5s后出现(例如)? 与财产的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
它会做到这一点。
@ Anbu.Karthik:刚刚做到了,但我想我已经知道了我的问题。只需要将'如果longPress.state == UIGestureRecognizerState.ended'改为'如果longPress.state == UIGestureRecognizerState.began'并且它做了诀窍。 我想星期一早上的眼睛帮助我看到,经过几个小时的搜索到我的代码:/ 无论如何,谢谢。 – Hawkydoky
多数民众赞成我所有的bro congrtz –
你的意思是在长按手势触发其选择器后显示0.5秒的警报? – thxou