iOS6与iOS7屏幕适配技巧
2016-08-21 17:47
302 查看
1.控制器的view是UIScrollView/UITableView/UICollectionView时(控制器是UITableViewController的时候)
- (void)viewDidLoad
{
[super viewDidLoad];
// #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
- (void)viewDidLoad
{
[super viewDidLoad];
// #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
相关文章推荐
- iOS6与iOS7屏幕适配技巧
- [操作系统]iOS6与iOS7屏幕适配技巧
- iOS6与iOS7屏幕适配技巧
- iOS6与iOS7屏幕适配技巧
- iOS6与iOS7屏幕适配技巧
- iOS6与iOS7屏幕适配技巧
- iOS6与iOS7屏幕适配技巧
- IOS6和IOS7的屏幕适配问题
- IOS6和IOS7的屏幕适配问题
- iOS- <项目笔记>iOS6 & iOS7屏幕图片适配
- APP IOS6 适配iOS7开发技巧
- 41.影响iOS6与iOS7屏幕适配的参数和因素
- iOS7 和iOS6的屏幕适配
- iOS开发实用技巧——屏幕适配研究
- iOS6和iOS7代码的适配(3)——坐标适配
- 如何写UI及屏幕适配的一些技巧
- iOS6 / iOS7 状态栏高度适配
- iOS6和iOS7代码的适配(3)——坐标适配
- 2017年1月29日 iOS开发技巧 - Size Class与iOS 8多屏幕适配(一)
- 如何让ios7的app同时适应ios6,即ios6与ios7的适配问题