简体   繁体   中英

using swipe gesture recognizer swipe from one viewcontroller to another

Swipe-Right

UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(slideToRightWithGestureRecognizer:)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:swipeRight];

Swipe-Left

UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(slideToLeftWithGestureRecognizer:)];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeLeft];

On ' slideToRightWithGestureRecognizer ' method i want to write code which opens abcViewController which has a viewcontroller on storyboard and same with ' slideToLeftWithGestureRecognizer ' to open xyzViewController which also has view controller on storyboard. Without using Navigation View Controller in the program

Should be very easy to accomplish:

When the ViewControllers are connected on your storyboard you could easily do it like this:

- (void)slideToLeftWithGestureRecognizer:(id)sender {
    [self performSegueWithIdentifier:@"myConnectionIdentifierHere"]
}

If not:

- (void)slideToLeftWithGestureRecognizer:(id)sender {
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"myStoryboardName" bundle:nil];
    UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"myViewControllerIdentifierHere"];
    [self presentViewController:vc animated:YES completion:nil];
}

Have you considered using UIPageViewController ? Or does it necessarily have to be a swipe and not a pan gesture (UIPageViewController provides navigation between view controllers using a pan gesture interactively).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM