如何在navigationcontroller中从下到上显示/解除viewcontroller?

时间:2016-08-01 11:43:19

标签: ios objective-c uinavigationcontroller show-hide presentviewcontroller

当我将viewController推送到navigationController时,我想从下到上显示动画?有没有想过这样做?

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

当前

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

关闭

[self dismissViewControllerAnimated:YES completion:nil];

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

3 个答案:

答案 0 :(得分:4)

不要链接故事板

  

使用此代码呈现ViewController

它会从下到上显示

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

使用此代码解除ViewController

它会从上到下解雇

[self dismissViewControllerAnimated:YES completion:nil];

enter image description here

答案 1 :(得分:3)

目标C:

  

从下到上呈现

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

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

从上到下解除

[self dismissViewControllerAnimated:YES completion:nil];

<强>夫特:

  

从下到上呈现

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

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

从上到下解除

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

答案 2 :(得分:1)

您可以像@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