美文网首页
present遇到的问题

present遇到的问题

作者: 请叫我魔法师 | 来源:发表于2019-09-29 08:03 被阅读0次

一、获取presentingViewController失败问题

最下层是tabbarVC,上面是几个navigationVC,在当前页面present一个控制器A,
发现A.presentingViewController不是当前显示的控制器,而是tabbarVC,后来查了查,找到了原因

在调用presentViewController:animated:completion:方法时,真正作为跳转的容器并不一定是调用这个方法的view controller,而是取决于modalPresentationStyle。例如,一个全屏的跳转必须由一个全屏的view controller来完成。如果当前的控制器不能满足,那么系统会自动沿着视图控制器的层级向上查找。

所以当前控制器和导航控制器都不是全屏的,实际是用了tabbarVC去present的。

解决:
需要用到设计present的

@property(nonatomic,assign) BOOL definesPresentationContext;
@property(nonatomic,assign) UIModalPresentationStyle modalPresentationStyle;

两个属性.
简单来说,如果把一个控制器的definesPresentationContext属性设置为YES,那么在需要进行UIModalPresentationCurrentContext类型的跳转的时候,UIKit会使用视图层级内的这个控制器来进行跳转。

aaa.definesPresentationContext = YES;
bbb.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[aaa presentViewController:navList animated:YES completion:nil];

二、其他用处

并且设置这两个属性,可以实现b页面的透明。

aaa.definesPresentationContext = YES;
bbb.modalPresentationStyle = UIModalPresentationOverCurrentContext;
bbb.view.backgroundColor = [UIColor clearColor];//直接设置b页面背景色
[aaa presentViewController:navList animated:YES completion:nil];

相关文章

网友评论

      本文标题:present遇到的问题

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