我正在创建快速应用程序并且我正在使用 UISwipegesture 我正在向上和向下滑动并且它的工作完美但是当用户向上或向下滑动时我将隐藏显示 View 并且它按预期隐藏和显示但是当滑动停止时我想要那个自动查看显示
让我展示我的代码以便更好地理解
代码
videDidLoad()
let swipe = UISwipeGestureRecognizer(target: self, action:
#selector(respondToSwipeGesture(gesture:)))
swipe.direction = UISwipeGestureRecognizer.Direction.up
swipe.delegate = self
self.view.addGestureRecognizer(swipe)
let swipe1 = UISwipeGestureRecognizer(target: self, action: #selector(respondToSwipeGesture(gesture:)))
swipe1.direction = UISwipeGestureRecognizer.Direction.down
swipe1.delegate = self
self.view.addGestureRecognizer(swipe1)
@objc func respondToSwipeGesture(gesture: UIGestureRecognizer) {
if let swipeGesture = gesture as? UISwipeGestureRecognizer {
switch swipeGesture.direction {
case UISwipeGestureRecognizer.Direction.up:
print("Swiped up")
viewFilter.isHidden = true
case UISwipeGestureRecognizer.Direction.down:
print("Swiped down")
viewFilter.isHidden = true
default:
break
}
}
}
在这里你可以看到在上下方向上我隐藏了 View 但是当滑动停止时我想要再次显示那个 View 所以我无法理解如何做到这一点可以帮助我
最佳答案
使用UIGestureRecognizer.State
appledoc
在你的选择器中做这样的事情
@objc func respondToSwipeGesture(gesture: UIGestureRecognizer) {
if let swipeGesture = gesture as? UISwipeGestureRecognizer {
switch swipeGesture.direction {
case UISwipeGestureRecognizer.Direction.up:
print("Swiped up")
viewFilter.isHidden = true
case UISwipeGestureRecognizer.Direction.down:
print("Swiped down")
viewFilter.isHidden = true
default:
break
}
// code for looking up which state the gesture currently is in.
switch swipeGesture.state {
case .ended, .failed:
viewFilter.isHidden = false
// list up other cases here
}
}
}
关于ios - 当滑动手势停止 View 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53493047/