简体   繁体   English

UIViewController从右到左过渡

[英]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:如果您正在使用情节提要,并且“第一”视图已嵌入在导航控制器中

  1. set storyboardID for the second view controller in storyboard (Eg. here storyboardID is same as the class name) storyboardID中的第二个视图控制器设置storyboardID ID(例如,这里的storyboardID与类名相同)

  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 情况2:如果您使用情节提要,但“第一视图”控制器未嵌入在导航控制器中:1.将“第一”视图嵌入Navigarion控制器中

1.1. 1.1。 Open storyboard file and select the First View Controller 打开情节提要文件,然后选择“ First View Controller”

1.2. 1.2。 Goto Editor->Embed In-> Navigation Controller. 转到编辑器->嵌入式->导航控制器。

  1. Then do the step Case:1's 2nd step. 然后执行步骤Case:1的第二步。

Case 3: If you are using XIB files and first view is not in navigation controller. 情况3:如果您使用的是XIB文件,并且第一视图不在导航控制器中。 1. For loading first view in AppDelegate.m application:didFnishLoading: method do as follows: 1.要在AppDelegate.m中加载第一视图,请执行以下操作:didFnishLoading:方法:

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. 因为您的问题中没有提到您使用哪种方法加载视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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