Reputation:
I am creating swift application and i am using UISwipegesture i am swiping up and down direction and its work perfectly but when usewr swipe up or down i will hide show view and it hide and show as expected but when swiping stopped i want that view show automatically
let me Show my code for better understanding
Code
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
}
}
}
here you can able to see that on up down direction i hide view but when swipe stop i want that again show that view so i cant under stand how to do that can any please help me
Upvotes: 1
Views: 145
Reputation: 9734
Get the ended state of UIGestureRecognizer
and then show the view. See this doc
@objc func respondToSwipeGesture(gesture: UIGestureRecognizer) {
if let swipeGesture = gesture as? UISwipeGestureRecognizer {
if swipeGesture.state == .ended {
viewFilter.isHidden = false
}
}
}
Upvotes: 0
Reputation: 8011
Use the UIGestureRecognizer.State
appledoc
In your selector do something like this
@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
}
}
}
Upvotes: 3
Reputation: 998
You can use state
for gesture recognizer:
@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
}
if swipeGesture.state == .ended {
viewFilter.isHidden = false
}
}
}
Upvotes: 0