需求如下:
1.firstVC使用push跳转到secondVC
2.secondVC使用present弹起thirdVC
3.thirdVC使用present弹起fourVC
4.fourVC界面点击按钮返回firstVC(根视图)
效果图
Untitled4.gif核心代码
最后一个present的vc需要返回主视图时调用
-(void)toRootViewController{
UITabBarController *tabBarController = (UITabBarController *)[UIApplication sharedApplication].delegate.window.rootViewController;
if ([self respondsToSelector:@selector(presentingViewController)]){
self.presentingViewController.view.alpha = 0;
[self.presentingViewController.presentingViewController dismissViewControllerAnimated:false completion:^{
for (UIViewController * vc in tabBarController.selectedViewController.childViewControllers) {
if ([vc isKindOfClass:[ViewController class]]) { // 第一个controller
[tabBarController.selectedViewController popToViewController:vc animated:false];
}
}
}];
}
}
网友评论