Search code examples
xcodestoryboarduiswipegesturerecognizer

How to change Storyboard animation from sliding up to down?


I have a program that slides up a page in which you can enter info into and when use my swipe gesture to go back it slides up. Is there a way to change the animation from sliding up to down?


Solution

  • Rather than using another modal segue to go back to the first page, use an IBAction along with dismissViewControllerAnimated:completion:

    First, delete your modal segue that goes back to the first page.

    Then, in your second page (UIViewController) where you have implemented the UISwipeGestureRecognizer, create the following in your .h and .m files:

    //secondPage.h
    
    - (IBAction)dismissViewControllerOnSwipe;
    

    //secondPage.m
     - (IBAction)dismissViewControllerOnSwipe
    {
        [self dismissViewControllerAnimated:YES completion:nil];    
    }
    

    Finally, go to your UISwipeGestureRecognizer in your storyboard and navigate to the connections inspector. Add the dismissViewControllerOnSwipe method under "Sent Actions" as shown below:

    Sent Actions

    This should make the animation slide down back to the "first page" after swiping downward.