我如何 present/dismiss viewcontroller 在导航控制器中从下到上?

How can i present/dismiss viewcontroller from bottom to top in navigationcontroller?

当我将 viewController 推送到 navigationController 时,我想从下到上显示动画?有人知道吗?

RegisterViewController *registerView = (RegisterViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"RegisterViewController"];

现在

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

关闭

[self dismissViewControllerAnimated:YES completion:nil];

有没有办法在 navigationController 中实现这个?

不要link故事板

Present ViewController with this code

会从下往上呈现

UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"MYUnicornViewController"]; // Change the view controller name
[self.navigationController presentViewController:vc animated:YES completion:nil];

Dismiss ViewController with this code

会从上到下dismiss

[self.navigationController dismissViewControllerAnimated:YES completion:nil];

Objective C:

Present from Bottom to Top

RegisterViewController *registerView = (RegisterViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"RegisterViewController"];

[self.navigationController presentViewController:registerView animated:YES completion:nil];

Dismiss from Top to Bottom

[self dismissViewControllerAnimated:YES completion:nil];

Swift:

Present from Bottom to Top

let registerView = self.storyboard?.instantiateViewController(withIdentifier: "RegisterViewController") as! RegisterViewController

self.navigationController?.present(registerView, animated: true, completion: nil)

Dismiss from Top to Bottom

self.navigationController?.dismiss(animated: true, completion: nil)

您可以像@PinkeshGjr 回答的那样呈现视图控制器, 我正在添加代码以添加没有@Pinkeshgjr 建议的自定义视图的导航栏。

相反,您可以简单地将视图控制器添加到导航控制器中并显示。

UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];//Change your storyboard name
UIViewController* myCopntroller = [storyBoard instantiateViewControllerWithIdentifier:@"myViewController"];//Your view controller
UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:myCopntroller];//Added in navigation controller
[self presentViewController:nav animated:YES completion:nil];//Present you viewcontroller