gpt4 book ai didi

ios - 如何使 UIAlertView 在 swift 3 中手指抬起之前出现?

转载 作者:行者123 更新时间:2023-11-30 12:11:12 27 4
gpt4 key购买 nike

我有一个 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.end 更改为 if longPress.state == UIGestureRecognizerState.began它会成功的。

关于ios - 如何使 UIAlertView 在 swift 3 中手指抬起之前出现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46031897/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com