iOS转场之present与dismiss的使用

present的使用方式
present只能是A present B , B present C , C present D这样的链式弹出。
不能A present B , A present C , A present D这样的叠加弹出,会报错。

dismiss的使用方法
dismiss是底部父VC的方法,由父类批量dismiss掉它所有的链式弹出的子VC,
如果在子类调用dismiss,它会关闭它自己,如D调用dismiss,D会退出,如果在中间调用dismiss,它会关闭它上面的批量部分,如C调用dismiss,C、D会退出。

presentedViewController属性与presentingViewController属性
UIViewController下presentedViewController属性和presentingViewController属性是用来表示A present B , B present C , C present D这样的链式弹出关系的。
它们表示的意义是:
presentedViewController是底部VC属性,表示下面VC拥有presentedViewController被弹出的VC。
presentingViewController是顶部VC属性,表示上面VC拥有presentingViewController弹出它的VC。
定义如下:
// The view controller that was presented by this view controller or its nearest ancestor.
@property(nullable, nonatomic,readonly) UIViewController *presentedViewController  API_AVAILABLE(ios(5.0));
// The view controller that presented this view controller (or its farthest ancestor.)
@property(nullable, nonatomic,readonly) UIViewController *presentingViewController API_AVAILABLE(ios(5.0));
举例如下:
A present B时,A页面在下面,B页面在上面
---------------------A弹B后---------------------
 A.presentingViewController (null)     
 A.presentedViewController B          
 B.presentingViewController A
 B.presentedViewController (null)
---------------------B弹C后---------------------
 A.presentingViewController (null)
 A.presentedViewController B
 B.presentingViewController A
 B.presentedViewController C
 C.presentingViewController B
 C.presentedViewController (null)
常见的问题场景
问题1:业务VC要present出SDK中的功能VC, SDK功能VC要present出子功能VC,当点击SDK中的功能VC的“X”或者子功能VC的“X”,都要让SDK页面完全退出。
简化问题为A present B , B present C 。关闭C时,BC要退出;关闭B时,BC要退出。

对于关闭C时,BC要退出;关闭B时,BC要退出需求可以调用B.presentedViewController dissmiss方法解决。

 

 

 

posted @ 2023-03-15 18:29  滴水微澜  阅读(326)  评论(0编辑  收藏  举报