ios7下的app都是全屏的,意思就是所有控制器的view默認都是從屏幕的(0,0)開始。
爲了達到全屏效果的app,官方爲UIviewController增加了幾個屬性:
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,意思大概是邊緣向四周展開
edgesForExtendedLayout 值是結構體,默認值是 UIRectEdgeAll,
也就是說,當一個控制器要往父控制器添加的時候,上下左右填充滿整個屏幕。
例如1:
UIViewController添加到uiNavController上時,uiviewcontroller的y值 == 狀態欄的的y
這時候設置
self.edgesForExtendedLayout = UIRectEdgeNone;
uiviewcontroller的y值 == 導航欄y + 導航欄height
/*
這種情況還可以設置,導航欄的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://www.cnblogs.com/wangxiaofeinin/p/3532831.html?utm_source=tuicool&utm_medium=referral