美文网首页
self.view.frame从导航栏以下开始计算

self.view.frame从导航栏以下开始计算

作者: 紫嫣沁 | 来源:发表于2021-08-26 14:49 被阅读0次

    在iOS 7中,苹果引入了一个新的属性,叫做[UIViewController setEdgesForExtendedLayout:],它的默认值为UIRectEdgeAll。当你的容器是navigation controller时,默认的布局将从navigation bar的顶部开始。这就是为什么所有的UI元素都往上漂移了44pt

    方法一:可以通过设置这个属性解决

    if([self respondsToSelector:@selector(edgesForExtendedLayout)]){

    self.edgesForExtendedLayout=UIRectEdgeNone;

    }

    UIRectEdgeBottom:  从navigationBar下面开始计算一直到屏幕底部;

    UIRectEdgeNone:从navigationBar下面开始计算一直到屏幕tabBar上部;

    UIRectEdgeTop:从navigationBar上面计算面开始计算一直到屏幕tabBar上部;

    UIRectEdgeAll:全部覆盖

    iOS7以上系统,self.navigationController.navigationBar.translucent默认为YES,self.view.frame.origin.y从0开始(屏幕最上部)。此时如果设置为UIRectEdgeNone,当给屏幕截图时由于navBar是透明的,会出现64像素的黑色区域。

    方法二:可以把导航栏的透明度设为NO

    self.navigationController.navigationBar.translucent = NO;

    相关文章

      网友评论

          本文标题:self.view.frame从导航栏以下开始计算

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