0
我有一個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)
}
}
}
@ Anbu.Karthik:剛剛做到了,但我想我已經知道了我的問題。只需要將'如果longPress.state == UIGestureRecognizerState.ended'改爲'如果longPress.state == UIGestureRecognizerState.began'並且它做了訣竅。 我想星期一早上的眼睛幫助我看到,經過幾個小時的搜索到我的代碼:/ 無論如何,謝謝。 – Hawkydoky
多數民衆贊成我所有的bro congrtz –
你的意思是在長按手勢觸發其選擇器後顯示0.5秒的警報? – thxou