简体   繁体   中英

UIViewController Transition from right to left

我正在从拳头viewController的按钮单击上打开第二个视图控制器,但它是从底部动画的。我想从右到左打开它。

Use

[self pushViewController:yourViewController animated:YES];

instead of

[self presentViewController:yourViewController animated:YES completion:nil];

The first piece of code pushes the second view controller in the screen from right to left.

The second line of code, which is what you have probably written in your app presents the view controller modally, meaning from bottom to top.

You may be presenting the second view controller on first view button tap.

The view transition from right to left will work when you do pushing a second view. For enable pushing the second view, at first your first view should be inside navigation controller. If your first view is already inside a navigation controller then do the following for pushing second view: Case 1: If your are using storyboard and First view is already embedded in Navigation controller

  1. set storyboardID for the second view controller in storyboard (Eg. here storyboardID is same as the class name)

  2. Do this code on your button tap of first view:

      SecondViewController *secondViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"]; [self.navigationController pushViewController:secondViewController animates:YES]; 

Case 2: If you are using storyboard but First view controller is not embedded in Navigation Controller: 1. Embed the First view in Navigarion controller

1.1. Open storyboard file and select the First View Controller

1.2. Goto Editor->Embed In-> Navigation Controller.

  1. Then do the step Case:1's 2nd step.

Case 3: If you are using XIB files and first view is not in navigation controller. 1. For loading first view in AppDelegate.m application:didFnishLoading: method do as follows:

FirstViewController *firstViewController = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
self.window.rootViewController = navigationController;
  1. Then for pushing second view on first view button do as follows:

      SecondViewController *secondViewController = [[FirstViewController alloc] initWithNibName:@"SecondViewController" bundle:nil]; [self.navigationController pushViewController:secondViewController animates:YES]; 

If this is not helpful, then just post what you did exactly then exact solution can be given. Because what approach you are using to load view is not mentioned in your question.

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