3

我想從底部到頂部顯示動畫時,我將viewController推送到navigationController?有沒有想法做到這一點?如何在navigationcontroller中從下到上顯示/關閉viewcontroller?

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

目前

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

辭退

[self dismissViewControllerAnimated:YES completion:nil]; 

有沒有辦法在navigationController來實現這一目標?

回答

4

不要使用此代碼

它將從底部出示鏈接故事板

當前視圖控制器頂部

UIViewController *vc; 
    vc = [self.storyboard instantiateViewControllerWithIdentifier:@"VC1"]; 
    [self.navigationController presentViewController:vc animated:YES completion:nil]; 

辭退的ViewController使用此代碼

它將從頂部解僱上下

[self dismissViewControllerAnimated:YES completion:nil]; 

enter image description here

+0

哦!我很驚訝,但在這種情況下,它隱藏導航欄。 –

+0

爲什麼你不創建自定義設計,看起來像在該視圖控制器上的導航 – PinkeshGjr

+0

它隱藏導航欄,因爲這種解決方案,你是模態呈現,而不是推到導航堆棧上。 – william205

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 
相關問題