I am opening second view controller on button click from fist viewController,but its animating from bottom.I want to open it in right to left.
我打开第二个视图控制器按钮点击从拳头viewController,但它从底部动画。我想从右到左打开它。
2 个解决方案
#1
0
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. herestoryboardID
is same as the class name)为storyboard中的第二个视图控制器设置storyboardID(例如,这里的storyboardID与类名相同)
-
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. Open storyboard file and select the First View Controller
1.1。打开故事板文件并选择First View Controller
1.2. Goto Editor->Embed In-> Navigation Controller.
1.2。转到编辑器 - >嵌入 - >导航控制器。
- Then do the step Case:1's 2nd step.
- 然后执行步骤Case:1的第2步。
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:
情况3:如果您正在使用XIB文件,并且第一个视图不在导航控制器中。 1.在AppDelegate.m应用程序中加载第一个视图:didFnishLoading:方法执行如下操作:
FirstViewController *firstViewController = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
self.window.rootViewController = navigationController;
-
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.
如果这没有用,那么只需发布您所做的精确解决方案即可。因为在您的问题中没有提到您用于加载视图的方法。
#2
0
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.
第二行代码,您可能在应用程序中编写的代码以模态方式呈现视图控制器,这意味着从下到上。
#1
0
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. herestoryboardID
is same as the class name)为storyboard中的第二个视图控制器设置storyboardID(例如,这里的storyboardID与类名相同)
-
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. Open storyboard file and select the First View Controller
1.1。打开故事板文件并选择First View Controller
1.2. Goto Editor->Embed In-> Navigation Controller.
1.2。转到编辑器 - >嵌入 - >导航控制器。
- Then do the step Case:1's 2nd step.
- 然后执行步骤Case:1的第2步。
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:
情况3:如果您正在使用XIB文件,并且第一个视图不在导航控制器中。 1.在AppDelegate.m应用程序中加载第一个视图:didFnishLoading:方法执行如下操作:
FirstViewController *firstViewController = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
self.window.rootViewController = navigationController;
-
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.
如果这没有用,那么只需发布您所做的精确解决方案即可。因为在您的问题中没有提到您用于加载视图的方法。
#2
0
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.
第二行代码,您可能在应用程序中编写的代码以模态方式呈现视图控制器,这意味着从下到上。