美文网首页
ios 连续两次跳转,但需要去除第一次跳转动画

ios 连续两次跳转,但需要去除第一次跳转动画

作者: noyya | 来源:发表于2018-10-30 13:07 被阅读26次

需求背景:

从A界面跳转到C,C界面点击返回到B界面,B点击返回回到A界面。

第一种情况:push + push
//在A控制器
[self.navigationController pushViewController:C animated:YES];
//获取到导航控制器下的所有子控制器,设置好顺序。
NSMutableArray*tempMarr =[NSMutableArray arrayWithArray:self.navigationController.viewControllers];
//当前可以看到顺序 tempMarr :[A,C]
[tempMarr insertObject:B atIndex:tempMarr.count- 1];
[self.navigationController setViewControllers:tempMarr animated:YES];
//添加之后顺序tempMarr:[A,B,C],之后即可实现;
第二种情况:push + present
//更简单 不需要获取导航控制器,在A控制器中直接present到C控制器
[A presentViewController:C animated:YES completion:^{
        //push去除动画效果
        [self.navigationController pushViewController:B animated:NO];
    }];
第三种情况:present + push
[A presentViewController:[[UINavigationController alloc]initWithRootViewController:C] animated:YES completion:^{
            NSMutableArray*tempMarr =[NSMutableArray arrayWithArray:C.navigationController.viewControllers];
            [tempMarr insertObject:B atIndex:tempMarr.count -1 ];
            [C.navigationController setViewControllers:tempMarr animated:YES];
    }];

//这里值得注意的是此时这三个界面 是B,C在同一个导航控制器,A单独在一个导航控制器,所以当C pop回到B的时候。B需要自定义一个返回到A的 按钮
[self dismissViewControllerAnimated:YES completion:nil];

第四种情况 present + present
小知识点:A presentViewController 到B 后,
           *A.presentedViewController就是B,
           *B.presentingViewController就是A

其他的遇到这种情况的说明你得换个思维思考,换不了,说明是需求给的有问题,你可以去找老板谈谈,我也不会 ! 有会的大佬请指教

相关文章

网友评论

      本文标题:ios 连续两次跳转,但需要去除第一次跳转动画

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