美文网首页
模态Model跳转和Push跳转的混合实现原理

模态Model跳转和Push跳转的混合实现原理

作者: BeeQiang | 来源:发表于2017-10-31 11:48 被阅读0次

1、在模态Model推出的视图中Push下一个带导航栏的视图,然后返回首页(A -> B ->C -> A)

核心代码展示:

/** 这里用到的核心处理办法是 */
/** 1.在A控制器模态Model推出B控制器的时候先给B控制器包装一个导航控制器 */

UINavigationController *ANavigationController = [[UINavigationController alloc] initWithRootViewController:[[BViewController alloc] init]];
[self presentViewController:ANavigationController animated:YES completion:nil];

/** 2.在B控制器遵守UINavigationControllerDelegate实现代理协议,隐藏当前控制器的导航栏 */
#pragma mark - UINavigationControllerDelegate

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    // 判断要显示的控制器是否是自身控制器
    BOOL isShowMyController = [viewController isKindOfClass:[self class]];
    [self.navigationController setNavigationBarHidden:isShowMyController animated:YES];
}

#pragma mark - Push出C控制器
[self.navigationController pushViewController:[[CViewController alloc] init] animated:YES];

/** 3.在C控制器里面可直接在返回按钮方法里DisMiss */
[self.navigationController dismissViewControllerAnimated:YES completion:nil];

希望能够帮助你

相关文章

网友评论

      本文标题:模态Model跳转和Push跳转的混合实现原理

      本文链接:https://www.haomeiwen.com/subject/ilfbpxtx.html