iOS7 edgesForExtendedLayout
作者:
iOS小虫下米 | 来源:发表于
2016-04-13 11:03 被阅读104次 [super viewDidLoad];
// Do any additional setup after loading the view.
if (OSVersionIsAtLeastiOS7()) {
if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) {
self.edgesForExtendedLayout = UIRectEdgeNone;
}
}
}```
[答案来源](http://beyondvincent.com/blog/2013/11/19/122-working-with-ios-6-and-7/)
原因:
在iOS 7中,苹果引入了一个新的属性,叫做 `[UIViewController setEdgesForExtendedLayout:]`
,它的默认值为`UIRectEdgeAll`
。当你的容器是navigation controller时,默认的布局将从navigation bar的顶部开始。这就是为什么所有的UI元素都往上漂移了`44pt`。
修复这个问题的快速方法就是在方法- (void)viewDidLoad
中添加如下一行代码:
`self.edgesForExtendedLayout = UIRectEdgeNone;`
这样问题就修复了。
本文标题: iOS7 edgesForExtendedLayout
本文链接:https://www.haomeiwen.com/subject/qyiwlttx.html
网友评论