在iOS 7中,苹果引入了一个新的属性,叫做[UIViewController setEdgesForExtendedLayout:],它的默认值为UIRectEdgeAll。当你的容器是navigation controller时,默认的布局将从navigation bar的顶部开始。这就是为什么所有的UI元素都往上漂移了44pt。有时会加上顶部tool bar的高度 20, 20+44 = 64
实例程序在
navigation controller的根控制器下创建两个tableView
出现的问题:
解决问题
self.edgesForExtendedLayout = UIRectEdgeNone;//设置navgationcontrllor的漂移问题,和navgation的穿透问题在iOS 7中,苹果引入了一个新的属性,叫做[UIViewController setEdgesForExtendedLayout:],它的默认值为UIRectEdgeAll。当你的容器是navigation controller时,默认的布局将从navigation bar的顶部开始。这就是为什么所有的UI元素都往上漂移了44pt。有时会加上顶部tool bar的高度 20, 20+44 = 64
CGRect viewBounds = self.view.bounds;
float navBarHeight = self.navigationController.navigationBar.frame.size.height + 20;
viewBounds.size.height = ([[UIScreen mainScreen] bounds].size.height) - navBarHeight;
self.view.bounds = viewBounds;