iOS 6 和iOS7的适配

一、没有包装任何导航控制器或者UITabBarController

1.控制器的view是UIScrollView/UITableView/UICollectionView时(控制器是UITableViewController的时候)

- (void)viewDidLoad

{

[superviewDidLoad];

// #ifdef __IPHONE_7_0是判断是否运行在Xcode5环境下,如果在Xcode5环境下才有下面的代码

#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 &&没有包装导航控制器

if([[UIDevice currentDevice].systemVersion floatValue] >=7.0&&self.navigationController ==nil) {

CGFloat top = [self.topLayoutGuide length];

//是否能滚动

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

二、包装有导航控制器的情况

1>控制器的view不是UIScrollView

#ifdef __IPHONE_7_0

if([[UIDevice currentDevice].systemVersion floatValue] >=7.0) {

self.edgesForExtendedLayout = UIRectEdgeNone;

}

#endif

2>控制器的view是UIScrollView

不需要写额外的代码适配

三、其他情况(上述情况不用死机,只要掌握以下几点规律)

1.想让view的内容往下挪动

1> UIView设置bounds的y值

2> UIScrollView设置contentInset的top值

2.防止子控制器的view被导航栏或者tabbar遮住

self.edgesForExtendedLayout = UIRectEdgeNone;

四、多控制器嵌套处理

1.当多重控制器嵌套的时候,最合理的方案是:UITabBarController内部嵌套UINavigationController

2.当UITableViewController的直接父控制器是UINavigationController时,不需要编写任何适配代码

3.其他非UITableViewController需要加上适配代码

#ifdef __IPHONE_7_0

if([[UIDevice currentDevice].systemVersion floatValue] >=7.0) {

self.edgesForExtendedLayout = UIRectEdgeNone;

}

#endif

你可能感兴趣的:(iOS 6 和iOS7的适配)