简体   繁体   English

如何在导航控制器中从下到上呈现/关闭视图控制器?

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

I want to show animation from bottom to top when i am pushing viewController to navigationController?Do any have idea to do it?当我将 viewController 推送到 navigationController 时,我想从下到上显示动画?有人知道这样做吗?

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

Present礼物

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

Dismiss解雇

[self dismissViewControllerAnimated:YES completion:nil];

Is there any way to achieve this in navigationController?有什么办法可以在导航控制器中实现这一点吗?

Don't link Storyboard不要链接故事板

Present ViewController with this code使用此代码呈现 ViewController

It Will Present from bottom to top它会从下到上呈现

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

Dismiss ViewController with this code使用此代码关闭 ViewController

It Will dismiss from top to bottom它会从上到下解散

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

在此处输入图片说明

Objective C:目标 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)

You can present the view controller like as answered by @PinkeshGjr, I am adding code to add navigation bar without the custom view suggested by @Pinkeshgjr.您可以像@PinkeshGjr 所回答的那样呈现视图控制器,我正在添加代码以添加导航栏,而没有@Pinkeshgjr 建议的自定义视图。

Instead you can simply add your view controller in Navigation controller and present.相反,您可以简单地在导航控制器中添加您的视图控制器并呈现。

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

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

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