iOS 多个模态视图相互跳转

这次的需求是扫码验证功能,需要一个扫码界面,一个输入界面,一个验证成功界面相互跳转。因为两两界面都存在相互跳转,并且界面的UI类似弹窗格式,所以我打算用模态跳转方法实现。实现思路是:跳转时,先dissmiss当前的,用当前视图的presentingViewController模态出下一个界面。

到这我们先了解下一个模态出的视图的presentingViewController和presentedViewController,

 A->B 则B的presentingViewController是A, A的presentedViewController是B

以下是示意代码

- (void)presentSuccVC:(ProofSuccModel *)model{
    [self dismissViewControllerAnimated:NO completion:nil];
    ProofSuccViewController *vc = [[ProofSuccViewController alloc]init];
    vc.modalPresentationStyle = UIModalPresentationOverCurrentContext;
    vc.model = model;
    [self.presentingViewController presentViewController:vc animated:YES completion:nil];
}

在开发中还有一种情况就是展开出多个视图,然后全部返回,我们知道如果是push的话,可以直接用返回rootViewCtroller的方法,而模态没有这种方法我们应该怎么做呢

- (void)dismiss:(id)sender
{
    if (self.navigationController.presentingViewController) {
        [self.navigationController dismissViewControllerAnimated:YES completion:nil];
    }else{
        [self.navigationController popViewControllerAnimated:YES];
    }
    
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容