最新要闻

广告

手机

iphone11大小尺寸是多少?苹果iPhone11和iPhone13的区别是什么?

iphone11大小尺寸是多少?苹果iPhone11和iPhone13的区别是什么?

警方通报辅警执法直播中被撞飞:犯罪嫌疑人已投案

警方通报辅警执法直播中被撞飞:犯罪嫌疑人已投案

家电

看热讯: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方法解决。

关键词: