iOS7 兼容适配 如何判断版本号
2015-01-20 11:14
225 查看
很多时候我们需要做不同版本的适配,所以首先要进行版本选择
方式一
方式二
iOS7 中新增了
现在
在iOS7中自定义的
例如
edgesForExtendedLayout是一个类型为UIExtendedEdge的属性,指定边缘要延伸的方向。 因为iOS7鼓励全屏布局,它的默认值很自然地是UIRectEdgeAll,四周边缘均延伸,就是说,如果即使视图中上有navigationBar,下有tabBar,那么视图仍会延伸覆盖到四周的区域。
如果把视图做如下设置,那么视图就不会延伸到这些bar的后面了.
一些相关的属性
在iOS7中如果视图里面存在唯一一个UIScrollView或其子类View,那么它会自动设置相应的内边距,这样可以让scroll占据整个视图,又不会让导航栏遮盖.
最后一个介绍的新属性是extendedLayoutIncludesOpaqueBars,这个属性指定了当Bar使用了不透明图片时,视图是否延伸至Bar所在区域,默认值时NO。
在iOS7 中UITableView的grouped延伸至两边变成了通栏.里面的控件用autolayout来兼容
PS: 一个不是问题的问题,在XCode5中如果是一个xib创建的grouped的tableView,将不会正常显示,需要重新初始化,例如
如果不为窗体指定着色,则会使用系统默认的颜色。
默认情况下,视图的着色是nil,意味着视图使用父级的着色。也就是说哪怕你不设置着色的话,视图也总能够获取到一个色值。
总的来说,最好在视图还没有显示到屏幕上之前指定它的着色。想让视图继承上个层级的着色的话,就将着色设置为nil。
如果你想要隐藏status bar, 或者用原来的方式修改status bar的颜色.在info.plist中增加这个属性,并且设置为
这个请参考 stackover flow
PS: 另一个不是问题的问题,把searchBar 当做tableView的header的时候,如果含有UISearchDisplayController,有时候会导致search bar消失. 目前没有找到很好的办法,目前重新初始化可以解决.
在iOS7之前UITablleViewCell中得contentView得superView就是UITableViewCell。但是在iOS7得时候,contentView得superView确实UITableViewCellScrollView.可以用以下代码来获取
方式一
<span class="line-number" style="color: inherit !important;">1</span> <span class="line-number" style="color: inherit !important;">2</span> <span class="line-number" style="color: inherit !important;">3</span> <span class="line-number" style="color: inherit !important;">4</span> <span class="line-number" style="color: inherit !important;">5</span> <span class="line-number" style="color: inherit !important;">6</span> <span class="line-number" style="color: inherit !important;">7</span> <span class="line-number" style="color: inherit !important;">8</span> <span class="line-number" style="color: inherit !important;">9</span> <span class="line-number" style="color: inherit !important;">10</span> <span class="line-number" style="color: inherit !important;">11</span> <span class="line-number" style="color: inherit !important;">12</span> <span class="line-number" style="color: inherit !important;">13</span> | NSUInteger DeviceSystemMajorVersion(); NSUInteger DeviceSystemMajorVersion() { static NSUInteger _deviceSystemMajorVersion = -1; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ _deviceSystemMajorVersion = [[[[[UIDevice currentDevice] systemVersion] componentsSeparatedByString:@"."] objectAtIndex:0] intValue]; }); return _deviceSystemMajorVersion; } #define MY_MACRO_NAME (DeviceSystemMajorVersion() < 7) } |
<span class="line-number" style="color: inherit !important;">1</span> <span class="line-number" style="color: inherit !important;">2</span> <span class="line-number" style="color: inherit !important;">3</span> <span class="line-number" style="color: inherit !important;">4</span> <span class="line-number" style="color: inherit !important;">5</span> | if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) { // Load resources for iOS 6.1 or earlier } else { // Load resources for iOS 7 or later } |
新的barTintColor
iOS7 中新增了barTintColor来取代原有的
tintColor,
现在
barTintColor表示对背景色的修改,
而原有的tintColor只修改对应bar上的按钮
自定义 UIBarButtonItem 偏移
在iOS7中自定义的 UIBarButtonItem所有的item向中间偏移了5个像素,所以需要修改
alignmentRectInsets来适配,
例如
<span class="line-number" style="color: inherit !important;">1</span> <span class="line-number" style="color: inherit !important;">2</span> <span class="line-number" style="color: inherit !important;">3</span> <span class="line-number" style="color: inherit !important;">4</span> <span class="line-number" style="color: inherit !important;">5</span> <span class="line-number" style="color: inherit !important;">6</span> <span class="line-number" style="color: inherit !important;">7</span> <span class="line-number" style="color: inherit !important;">8</span> <span class="line-number" style="color: inherit !important;">9</span> <span class="line-number" style="color: inherit !important;">10</span> <span class="line-number" style="color: inherit !important;">11</span> <span class="line-number" style="color: inherit !important;">12</span> <span class="line-number" style="color: inherit !important;">13</span><span class="line-number" style="color: inherit !important;">14</span> | - (UIEdgeInsets)alignmentRectInsets { UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, 0,0); if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7")) { if (self.isLeft) { insets = UIEdgeInsetsMake(0, 5.0f, 0, 0); } else { // IF_ITS_A_RIGHT_BUTTON insets = UIEdgeInsetsMake(0, 0, 0, 5.0f); } } return insets; } |
edgesForExtendedLayout 是什么
edgesForExtendedLayout是一个类型为UIExtendedEdge的属性,指定边缘要延伸的方向。 因为iOS7鼓励全屏布局,它的默认值很自然地是UIRectEdgeAll,四周边缘均延伸,就是说,如果即使视图中上有navigationBar,下有tabBar,那么视图仍会延伸覆盖到四周的区域。如果把视图做如下设置,那么视图就不会延伸到这些bar的后面了.
<span class="line-number" style="color: inherit !important;">1</span> | self.edgesForExtendedLayout = UIExtendedEdgeNone; |
<span class="line-number" style="color: inherit !important;">1</span> | automaticallyAdjustsScrollViewInsets = YES |
<span class="line-number" style="color: inherit !important;">1</span> | extendedLayoutIncludesOpaqueBars = YES |
grouped 的变化
在iOS7 中UITableView的grouped延伸至两边变成了通栏.里面的控件用autolayout来兼容PS: 一个不是问题的问题,在XCode5中如果是一个xib创建的grouped的tableView,将不会正常显示,需要重新初始化,例如
<span class="line-number" style="color: inherit !important;">1</span> <span class="line-number" style="color: inherit !important;">2</span> <span class="line-number" style="color: inherit !important;">3</span> <span class="line-number" style="color: inherit !important;">4</span> <span class="line-number" style="color: inherit !important;">5</span><span class="line-number" style="color: inherit !important;">6</span> | -(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ if(self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped]; self.tableView.backgroundView = nil; self.tableView.backgroundColor = TOP_VIEW_COLOR; self.tableView.dataSource = self; self.tableView.delegate = self; } return self; } |
一些情况下 window.tintColor 的使用
如果不为窗体指定着色,则会使用系统默认的颜色。默认情况下,视图的着色是nil,意味着视图使用父级的着色。也就是说哪怕你不设置着色的话,视图也总能够获取到一个色值。
总的来说,最好在视图还没有显示到屏幕上之前指定它的着色。想让视图继承上个层级的着色的话,就将着色设置为nil。
info.plist 中的View controller-based status bar appearance
如果你想要隐藏status bar, 或者用原来的方式修改status bar的颜色.在info.plist中增加这个属性,并且设置为NO
UITextView 的改变
这个请参考 stackover flow
消失的search bar
PS: 另一个不是问题的问题,把searchBar 当做tableView的header的时候,如果含有UISearchDisplayController,有时候会导致search bar消失. 目前没有找到很好的办法,目前重新初始化可以解决.<span class="line-number" style="color: inherit !important;">1</span> <span class="line-number" style="color: inherit !important;">2</span> <span class="line-number" style="color: inherit !important;">3</span> <span class="line-number" style="color: inherit !important;">4</span> <span class="line-number" style="color: inherit !important;">5</span><span class="line-number" style="color: inherit !important;">6</span> | -(void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; self.searchController = [[UISearchDisplayController alloc] initWithSearchBar:self.searchBar contentsController:self]; [self.searchController setDelegate:self]; [self.searchController setSearchResultsDataSource:self]; [self.searchController setSearchResultsDelegate:self]; } |
新的UITableViewCellScrollView
在iOS7之前UITablleViewCell中得contentView得superView就是UITableViewCell。但是在iOS7得时候,contentView得superView确实UITableViewCellScrollView.可以用以下代码来获取<span class="line-number" style="color: inherit !important;">1</span> <span class="line-number" style="color: inherit !important;">2</span> <span class="line-number" style="color: inherit !important;">3</span> <span class="line-number" style="color: inherit !important;">4</span> <span class="line-number" style="color: inherit !important;">5</span> <span class="line-number" style="color: inherit !important;">6</span> <span class="line-number" style="color: inherit !important;">7</span> <span class="line-number" style="color: inherit !important;">8</span> <span class="line-number" style="color: inherit !important;">9</span> <span class="line-number" style="color: inherit !important;">10</span> <span class="line-number" style="color: inherit !important;">11</span> <span class="line-number" style="color: inherit !important;">12</span> <span class="line-number" style="color: inherit !important;">13</span><span class="line-number" style="color: inherit !important;">14</span> | @implementation UIView (GetCellFromContentviewSubview) - (UITableViewCell *)getCellFromContentviewSubview { if ([[[self superview] superview] isKindOfClass:[UITableViewCell class]]) { return (UITableViewCell *)[[self superview] superview]; } else if ([[[[self superview] superview] superview] isKindOfClass:[UITableViewCell class]]) { return (UITableViewCell *)[[[self superview] superview] superview]; } else{ NSLog(@"something Panic happens"); } return nil; } @end |
相关文章推荐
- 如何判断客户端的浏览器类型和版本号
- Javascript判断浏览器版本和版本号,全兼容
- IOS7 兼容适配总结(一)
- 如何让ios7的app同时适应ios6,即ios6与ios7的适配问题
- iOS7布局适配兼容的一篇好文章!!必须转
- 如何判断客户端的浏览器类型和版本号
- IOS7 兼容适配总结
- IOS7 兼容适配总结(一)
- 如何判断iphone设备型号和ios系统版本号
- IOS7 适配以及向下兼容问题
- Javascript判断浏览器版本和版本号,全兼容
- 如何让你的App适配iOS7?
- iOS开发 -- IOS7界面兼容,从4.3到7.0兼容的NavigationBar ,IOS7 NavigationBar 适配
- IOS7 适配以及向下兼容问题
- IOS7 适配以及向下兼容问题
- c/s程序版本自动升级的问题,如何判断client端版本号是否最新,然后从指定ftp服务器down
- 用javascript判断IE版本号简单实用且向后兼容
- ios7适配——push时出现阴影时如何解决
- iOS7适配以及向下兼容
- IOS7 兼容适配总结