ios7下的app都是全屏的,意思就是全部控制器的view默认都是从屏幕的(0,0)开始。ios
为了达到全屏效果的app,官方为UIviewController增长了几个属性:app
1 @property(nonatomic,assign) UIRectEdge edgesForExtendedLayout NS_AVAILABLE_IOS(7_0); // Defaults to UIRectEdgeAll 2 @property(nonatomic,assign) BOOL extendedLayoutIncludesOpaqueBars NS_AVAILABLE_IOS(7_0); // Defaults to NO, but bars are translucent by default on 7_0. 3 @property(nonatomic,assign) BOOL automaticallyAdjustsScrollViewInsets NS_AVAILABLE_IOS(7_0); // Defaults to YES
一:
属性edgesForExtendedLayout,意思大概是边缘向四周展开iview
edgesForExtendedLayout 值是结构体,默认值是 UIRectEdgeAll,ui
也就是说,当一个控制器要往父控制器添加的时候,上下左右填充满整个屏幕。atom
例如1:设计
UIViewController添加到uiNavController上时,uiviewcontroller的y值 == 状态栏的的yblog
这时候设置 self.edgesForExtendedLayout = UIRectEdgeNone;io
uiviewcontroller的y值 == 导航栏y + 导航栏heighttable
/*ios7
这种状况还能够设置,导航栏的bar的透明度属性translucent为no
self.navigationController.navigationBar.translucent = NO;
translucent属性在ios6以前默认为no,
而在ios7下的导航栏默认倒是半透明的,为yes,因此该属性不会占据空间。
*/
例如2:
UITableViewController添加到UITabBarController上时,UITableViewController的底部一部分cell会被TabBar挡住
这时候设置self.edgesForExtendedLayout = UIRectEdgeNone;
TabBar的y值 == CGRectGetMaxY(UITableViewController)
二 :
self.extendedLayoutIncludesOpaqueBars = YES;意思展开包括状态栏
三:
self.automaticallyAdjustsScrollViewInsets = YES;
当设计到scrollView、tableview时,在设置完数据的时候,内部会改变contentInsets的top值为64 例如:group样式的tableView在有导航栏的控制器下,第0组的头部会多出一部分高度h缘由是 ios7下group样式的tabelView的第0组第0个cell,在tableview中的y值为35!!!
而且在设置完cell数据以后,系统默认会执行
self.automaticallyAdjustsScrollViewInsets = YES;
也就是tableview的contentInset.top = 64;因此 第0组第0行cell的y值 = 64 + 35.要达到第0组第0行cell的y值 = 导航栏底部 的效果。就要在cell设置数据以前,
tableView.contentInset = UIEdgeInsetsMake(- 35, 0, 0, 0);
这样在cell在设置完数据后,系统内部改变top值增长64,就刚好达到效果。若要达到每一个group头部等高效果,
tableView.sectionHeaderHeight = cellSectionHeight;
tableView.sectionFooterHeight = 0; tableView.contentInset = UIEdgeInsetsMake(cellSectionHeight - 35, 0, 0, 0);
原文:http://wyfpkx.blog.163.com/blog/static/17260843920142422043416/