簡體   English   中英

如何在導航控制器中從下到上呈現/關閉視圖控制器?

[英]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];

有什么辦法可以在導航控制器中實現這一點嗎?

不要鏈接故事板

使用此代碼呈現 ViewController

它會從下到上呈現

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

使用此代碼關閉 ViewController

它會從上到下解散

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

在此處輸入圖片說明

目標 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.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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM