Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

fabrum

macrumors member
Original poster
Jan 15, 2021
47
3
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?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.