一蕉扮、沒有包裝任何導(dǎo)航控制器或者UITabBarController
1.控制器的view是UIScrollView/UITableView/UICollectionView時(shí)(控制器是UITableViewController的時(shí)候)
- (void)viewDidLoad
{
[superviewDidLoad];
// #ifdef __IPHONE_7_0是判斷是否運(yùn)行在Xcode5環(huán)境下,如果在Xcode5環(huán)境下才有下面的代碼
#ifdef __IPHONE_7_0
if([[UIDevice currentDevice].systemVersion floatValue] >=7.0) {
self.tableView.contentInset = UIEdgeInsetsMake(20,0,0,0);
}
#endif
}
2.控制器的view是普通的UIView震捣,非UIScrollView
#ifdef __IPHONE_7_0
- (void)viewDidLayoutSubviews
{
// iOS7 &&沒有包裝導(dǎo)航控制器
if([[UIDevice currentDevice].systemVersion floatValue] >=7.0&&self.navigationController ==nil) {
CGFloat top = [self.topLayoutGuide length];
//是否能滾動(dòng)
if([self.view isKindOfClass:[UIScrollView class]]) {
UIScrollView *scroll = (UIScrollView *)self.view;
scroll.contentInset = UIEdgeInsetsMake(top, scroll.contentInset.left, scroll.contentInset.bottom, scroll.contentInset.right);
}else{
CGRect bounds =self.view.bounds;
bounds.origin.y =- top;
self.view.bounds = bounds;
}
}
}
#endif
二、包裝有導(dǎo)航控制器的情況
1>控制器的view不是UIScrollView
#ifdef __IPHONE_7_0
if([[UIDevice currentDevice].systemVersion floatValue] >=7.0) {
self.edgesForExtendedLayout = UIRectEdgeNone;
}
#endif
2>控制器的view是UIScrollView
不需要寫額外的代碼適配
三宰掉、其他情況(上述情況不用死機(jī)恐仑,只要掌握以下幾點(diǎn)規(guī)律)
1.想讓view的內(nèi)容往下挪動(dòng)
1> UIView設(shè)置bounds的y值
2> UIScrollView設(shè)置contentInset的top值
2.防止子控制器的view被導(dǎo)航欄或者tabbar遮住
self.edgesForExtendedLayout = UIRectEdgeNone;
四、多控制器嵌套處理
1.當(dāng)多重控制器嵌套的時(shí)候伶椿,最合理的方案是:UITabBarController內(nèi)部嵌套UINavigationController
2.當(dāng)UITableViewController的直接父控制器是UINavigationController時(shí)辜伟,不需要編寫任何適配代碼
3.其他非UITableViewController需要加上適配代碼
#ifdef __IPHONE_7_0
if([[UIDevice currentDevice].systemVersion floatValue] >=7.0) {
self.edgesForExtendedLayout = UIRectEdgeNone;
}
#endif