Code:
@IBAction func PanPerformed(_ sender: UIPanGestureRecognizer) {
if sender.state == .began || sender.state == .changed {
let translation = sender.translation(in: self.view).x
if translation > 0 { // swipe right for sideView
if viewConstraint.constant < 20 {
UIView.animate(withDuration: 0.2, animations: {self.viewConstraint.constant = self.viewConstraint.constant + translation
self.view.layoutIfNeeded() })
}
}
else { // swipe left
if viewConstraint.constant > -175 {
UIView.animate(withDuration: 0.2, animations: {self.viewConstraint.constant = self.viewConstraint.constant + translation
self.view.layoutIfNeeded() })
// self.viewConstraint.constant = self.viewConstraint.constant + translation
}
}
}
else if sender.state == .ended {
if viewConstraint.constant < -100 {
UIView.animate(withDuration: 0.2, animations: {self.viewConstraint.constant = -175
self.view.layoutIfNeeded() })
}
else {
UIView.animate(withDuration: 0.2, animations: {self.viewConstraint.constant = 0
self.view.layoutIfNeeded() })
}
}
This is for a Side Menu on the left side. How could I code it to have a right Side Menu too?