简体   繁体   中英

How can I make a programmatic segue transition from left to right?

I've created a UIButton that when pressed, takes my users to the home screen (acting as a "Back" button). Because I wanted to achieve this without the usual clunky navigation bar, I've used the below code. However when the button is pressed, the transition goes from right to left; how can I make the below segue transition from left to right (in a "back" motion)?

FullArticleViewController.m

-(IBAction)goBack:(id)sender {

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
    FullArticleViewController *yourViewController = (FullArticleViewController *)[storyboard instantiateViewControllerWithIdentifier:@"ArticlesViewController"];
    [self.navigationController pushViewController:yourViewController animated:YES];
}

Use this:

[self.navigationController popViewControllerAnimated:TRUE];

This will "pop" your navigation controller stack back one view controller. This will also prevent you from adding a view controller to the stack like you're currently doing.

You can pop multiple view controllers using something like this (just for reference):

UIViewController *viewToPopTo = [self.navigationController.viewControllers objectAtIndex:([self.navigationController.viewControllers indexOfObject:self] - 2)];
[self.navigationController popToViewController:viewToPopTo animated:TRUE]; //Pops back 2

In case you you pushed the FullArticleViewController using a UINavigationController, write:

[self.navigationController popViewControllerAnimated:YES];

If you presented it modally, write:

[self.presentingViewController dismissViewControllerAnimated:YES];

When using a UINavigationController object the Nav Bat will be visible by default, but you can hide it if you need.

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