gpt4 book ai didi

ios - 同时处理两个手势识别器

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

问题很简单:我有一个ViewController,上面有一个GestureRecognizer:

    panGR = UIPanGestureRecognizer(target: self,
action: #selector(handlePan(gestureRecognizer:)))
view.addGestureRecognizer(panGR)
在此 ViewController中,我还具有一个 class WhishlistTableViewController: UITableViewController,在该代码上我具有“滑动删除”功能:
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let deleteAction = UIContextualAction(style: .destructive, title: "Löschen") {[weak self] _, _, completionHandler in
self!.deleteWishDelegate?.deleteWish(indexPath)
completionHandler(true)
}
deleteAction.backgroundColor = .red
deleteAction.image = UIImage(systemName: "trash")
let configuration = UISwipeActionsConfiguration(actions: [deleteAction])
configuration.performsFirstActionWithFullSwipe = false
return configuration
}
这是我的 panGR的视频: Screenvideo
这是我的 handlePan函数:
// handle swqipe down gesture
@objc private func handlePan(gestureRecognizer:UIPanGestureRecognizer) {
// calculate the progress based on how far the user moved
let translation = panGR.translation(in: nil)
let progress = translation.y / 2 / view.bounds.height

switch panGR.state {
case .began:
// begin the transition as normal
self.dismissView()
break
case .changed:

Hero.shared.update(progress)

default:
// finish or cancel the transition based on the progress and user's touch velocity
if progress + panGR.velocity(in: nil).y / view.bounds.height > 0.3 {
self.dismissView()
Hero.shared.finish()
} else {
Hero.shared.cancel()
}
}
}
问题在于这两个碰撞。仅当我禁用其他 GestureRecognizer时,“刷卡删除”才有效。为什么会这样,我该如何解决呢?

最佳答案

您应该尝试一下。

class YourViewController: UIViewController, UIGestureRecognizerDelegate
在viewDidLoad中
yourGesture.delegate = self
最后
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return true

// If you wish to do conditionally.
/*if (gestureRecognizer is UIPanGestureRecognizer || gestureRecognizer is UIRotationGestureRecognizer) {
return true
} else {
return false
}*/
}

关于ios - 同时处理两个手势识别器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63077016/

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