Swift3, I want to be able to open both pages when I swipe.

Asked 2 years ago, Updated 2 years ago, 61 views

If you swipe with the Swipe Gesture Recognizer on Swift3, you can only open right (right-to-left screen transition) no matter which way you swipe.Please let me know if there is a way to transition the screen from the left.

override func viewDidLoad(){
    super.viewDidLoad()

    // Swipe to the left
    let leftSwipe=UISwipeGestureRecognizer(target:self, action:#selector(swipeAction(swipe:)))
    leftSwipe.direction=UISwipeGestureRecognizerDirection.left
    self.view.addGestureRecognizer (leftSwipe)
    // Swipe to the right
    let rightSwipe=UISwipeGestureRecognizer (target:self, action:#selector(swipeAction(swipe:)))
    rightSwipe.direction=UISwipeGestureRecognizerDirection.right
    self.view.addGestureRecognizer (rightSwipe)
}


   func swipeAction (swipe:UISwipeGestureRecognizer) {
    switchswipe.direction{
    case UISwipeGestureRecognizerDirection.right:
        performSegue(withIdentifier: "backView", sender:self)
    case UISwipeGestureRecognizerDirection.left:
        performSegue(withIdentifier: "goView", sender:self)
    default:
        break
    }
}

swift swift3

2022-09-30 15:32

2 Answers

PageViewController enables you to implement Gesture or Animation without having to implement anything (although I'm not sure if it's appropriate for the purpose of the question).


2022-09-30 15:32

Swipe Gesture Recognizer has nothing to do with screen transition animation.
(Swipe Gesture Recognizer does not change the transition animation naturally.)

You can implement your own original screen transition animation using UIViewControllerAnimatedTransitioning or UIViewControllerTransitioningDelegate.


2022-09-30 15:32

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.