简体   繁体   English

如何将多个视图控制器推入UINavigation但只显示动画一次?

[英]How to push multiple view controllers into UINavigation but only show animation once?

Actually, I know how to push multiple viewControllers. 实际上,我知道如何推送多个viewControllers。 My question focus on the animation.In a UINavigationcontroller, I try to push two viewControllers. 我的问题集中在动画上。在UINavigationcontroller中,我尝试推送两个viewControllers。 And I cancel the animation of the first push. 我取消了第一次推动的动画。 However, in iPhone 6, iOS9.0 simulator, and iphone6 plus iOS9.0 real device, two animations are visible... My code is following: 但是,在iPhone 6,iOS9.0模拟器和iphone6加iOS9.0真实设备中,可以看到两个动画...我的代码如下:

UINavigationController *a = (UINavigationController *)(self.tabBarController.selectedViewController);
Second11ViewController *view11 = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"second1"];
Second22ViewController *view22 = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"second2"];
view11.hidesBottomBarWhenPushed = YES;
view22.hidesBottomBarWhenPushed = YES;
[a pushViewController:view11 animated:NO];
[a pushViewController:view22 animated:YES];

Any trick to do this. 这样做的任何技巧。 I want to show animation exactly once, like I just push one viewController (actually two).. 我想要一次显示动画,就像我只推一个viewController(实际上是两个)..

Try to use 尝试使用

[a setViewControllers:@[view11, view22] animated:YES];

Hope this would be help to you :) 希望这会对你有所帮助:)

Exactly, view11 will not be loaded before you pop out view22. 确切地说,在弹出view22之前,不会加载view11。

You can push the view controller you want to be on screen at the end and animate it. 您可以在最后按下想要在屏幕上显示的视图控制器并为其设置动画。 For adding the others into the navigation stack try to play around with self.navigationController.viewControllers in the viewDidLoad of the finally displayed view controller. 要将其他人添加到导航堆栈,请尝试在最终显示的视图控制器的viewDidLoad中使用self.navigationController.viewControllers

In your code: 在你的代码中:

UINavigationController *a = (UINavigationController *)self.tabBarController.selectedViewController;
Second11ViewController *view11 = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"second1"];
Second22ViewController *view22 = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"second2"];
view11.hidesBottomBarWhenPushed = YES;
view22.hidesBottomBarWhenPushed = YES;

[a pushViewController:view22 animated:YES];

And in Second22ViewController 's viewDidLoad : Second22ViewControllerviewDidLoad

NSMutableArray *viewControllers = self.navigationController.viewControllers.mutableCopy;
id lastViewController = [viewControllers lastObject];
[viewControllers removeLastObject];
[viewControllers addObject:/*an instance of the view controller in between*/];
[viewControllers addObject:lastViewController];
self.navigationController.viewControllers = viewControllers.copy;

But be careful: After you go back in the navigation (tap back button) from Second22ViewController , the viewDidLoad of Second11ViewController will be invoked, therefore care about infinite loops (I mean do not add a view controller in between with the same type of the finally visible one). 但要小心:你去后回导航(按返回键)从Second22ViewController ,在viewDidLoadSecond11ViewController将被调用,因此关心的无限循环(我的意思是在两者之间与同一类型的,终于不用添加视图控制器可见一个)。

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

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