原文地址 http://blog.sina.com.cn/s/blog_1410870560102wu9a.htmlhtml
在iOS 7中,苹果引入了一个新的属性,叫作[UIViewController setEdgesForExtendedLayout:],它的默认值为UIRectEdgeAll。当你的容器是navigation controller时,默认的布局将从navigation bar的顶部开始。这就是为何全部的UI元素都往上漂移了44pt。有时会加上顶部tool bar的高度 20, 20+44 = 64。并且下面tabbar也缩进的49布局
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. if (OSVersionIsAtLeastiOS7()) { if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) { self.edgesForExtendedLayout = UIRectEdgeNone; } } }
此时只须要把self.navigationController.navigationBar.translucent=NO便可,不须要加代码self.edgesForExtendedLayout;code
iOS7以后也增长了一个self.tabBarController.tabBar.translucent的属性,默认为YES。当应用同时使用navBar和TabBar的时候。设置self.tabBarController.tabBar.translucent=NO而且self.navigationController.navigationBar.translucent=NO时候,获得self.view.frame--->{{0, 64}, {320, 455}}。视图的高度也改变为navBar和tabBar之间的455像素。当self.navigationController.navigationBar.translucent=YES而且self.tabBarController.tabBar.translucent=NO的时候self.view.frame--->{{0, 0}, {320, 519}};其都为YES的时候self.view.frame--->{{0, 0}, {320, 568}};htm
注意:设置self.edgesForExtendedLayout = UIRectEdgeNone;的时候会使得navBar和tabBar都不占空间。self.view.frame--->{{0, 64}, {320, 455}}。此时iOS7默认navBar和tabBar都是透明的。截图的时候须要注意。blog