iOS6与iOS7屏幕适配技巧
2014-04-03 13:14
363 查看
一、没有包装任何 导航控制器 或者UITabBarController
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
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
相关文章推荐
- iOS6与iOS7屏幕适配技巧
- iOS6与iOS7屏幕适配技巧
- [操作系统]iOS6与iOS7屏幕适配技巧
- iOS6与iOS7屏幕适配技巧
- iOS6与iOS7屏幕适配技巧
- iOS6与iOS7屏幕适配技巧
- iOS6与iOS7屏幕适配技巧
- APP IOS6 适配iOS7开发技巧
- iOS- <项目笔记>iOS6 & iOS7屏幕图片适配
- 41.影响iOS6与iOS7屏幕适配的参数和因素
- IOS6和IOS7的屏幕适配问题
- IOS6和IOS7的屏幕适配问题
- iOS7 和iOS6的屏幕适配
- iOS6的控制屏幕旋转技巧
- iOS6和iOS7代码的适配(1)
- 关于如何写UI及屏幕适配的一些技巧(下)——颜婧
- ios6与ios7及之后适配的常见问题
- iOS6和iOS7代码的适配(2)——status bar
- 如何解决iOS6、iOS7 3.5寸和4.0寸屏的适配问题?不要写两个xib文件
- ios项目适配ios6 ios7