swift : show another view controller on swipe up in first view controller

后端 未结 2 1496
日久生厌
日久生厌 2021-02-04 17:24

Hi I checked many questions regarding swiping in SO but have doubts .

In my app I have two pages 1. user view controller 2. question view controller

user page l

2条回答
  •  暖寄归人
    2021-02-04 17:40

    You can achieve this using Auto-layout and Swipe Gesture. Tricky part is setting constraints to your view. Add a negative of height constant constraint to your view so that it does not show in view.

    @IBOutlet weak var yourViewBottomConstraint: NSLayoutConstraint! //Create IBOutlet of bottom Contraint to YourView
    
    let swipeUp = UISwipeGestureRecognizer() // Swipe Up gesture recognizer
    let swipeDown = UISwipeGestureRecognizer() // Swipe Down gesture recognizer OR You can use single Swipe Gesture
    

    Than in your viewDidLoad()

    Override func viewDidLoad() {
    // Swipe Gesture
            swipeUp.direction = UISwipeGestureRecognizerDirection.up
            swipeUp.addTarget(self, action: "swipedViewUp")
            drawerButton.addGestureRecognizer(swipeUp) // Or assign to view
    
            swipeDown.direction = UISwipeGestureRecognizerDirection.down
            swipeDown.addTarget(self, action: "swipedViewDown")
            drawerButton.addGestureRecognizer(swipeDown) // Or assign to view
    }
    

    And methods to swipe view

     // Toggle Swipe Action for imagesContainer
    func swipedViewUp(){
    
        self.yourViewBottomConstraint.constant = +90 // Or set whatever value
    
        print("Swiped Up")
    }
    
    func swipedViewDown(){
    
        self.yourViewBottomConstraint.constant = -90 // Or Set whatever value
    
    
        print("Swiped Down")
    }
    

提交回复
热议问题