iOS 8 初上手 牛刀小试

移动开发 iOS
本次iOS 8改变了一些细节,包括UIWindow的bounds发生变化(Window本身发生了旋转)等等,本篇还为大家整理了安装iOS 8 beta版本注意事项以及QR Code支持的相关内容。

1、UIWindow的bounds发生变化(Window本身发生了旋转)

iOS 7之前Window的bounds不会随着方向而变化,但是到了iOS 8以后,随着设备方向的旋转,window.bounds.size.width和window.bounds.size.height也会相应发生变化。

做个很简单的测试,代码如下:

  1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
  2.     // Override point for customization after application launch. 
  3.      
  4.     [[NSNotificationCenter defaultCenter] addObserver:self 
  5.                                              selector:@selector(orientationChanged:) 
  6.                                                  name:UIDeviceOrientationDidChangeNotification 
  7.                                                object:nil]; 
  8.      
  9.     return YES; 
  10.  
  11. - (void)orientationChanged:(NSNotification*)noti { 
  12.      
  13.     UIDeviceOrientation orientation = [UIDevice currentDevice].orientation; 
  14.     NSString *orientationDes = nil; 
  15.     switch (orientation) { 
  16.         case UIDeviceOrientationLandscapeLeft: 
  17.             orientationDes = @"UIInterfaceOrientationLandscapeRight"
  18.             break
  19.         case UIDeviceOrientationLandscapeRight: 
  20.             orientationDes = @"UIInterfaceOrientationLandscapeLeft"
  21.             break
  22.         case UIDeviceOrientationPortrait: 
  23.             orientationDes = @"UIInterfaceOrientationPortrait"
  24.             break
  25.         case UIDeviceOrientationPortraitUpsideDown: 
  26.             orientationDes = @"UIInterfaceOrientationPortraitUpsideDown"
  27.             break
  28.         default
  29.             orientationDes = @""
  30.             break
  31.     } 
  32.      
  33.     NSLog(@"system ver: %@, \rorientaion: %@, \rwindow bounds: %@"
  34.           [UIDevice currentDevice].systemVersion, 
  35.           orientationDes, 
  36.           NSStringFromCGRect(self.window.bounds)); 

示例代码很简单,新建一个工程,然后在delegate中直接添加以上代码即可。

iOS 8上运行结果为:

  1. 2014-06-04 09:26:32.016 SviOS8[4143:61114] system ver: 8.0, 
  2. orientaion: UIInterfaceOrientationLandscapeRight, 
  3. window bounds: {{0, 0}, {320, 480}} 
  4. 2014-06-04 09:26:34.788 SviOS8[4143:61114] system ver: 8.0, 
  5. orientaion: UIInterfaceOrientationPortrait, 
  6. window bounds: {{0, 0}, {480, 320}} 
  7. 2014-06-04 09:26:35.791 SviOS8[4143:61114] system ver: 8.0, 
  8. orientaion: UIInterfaceOrientationLandscapeLeft, 
  9. window bounds: {{0, 0}, {320, 480}} 
  10. 2014-06-04 09:26:47.468 SviOS8[4143:61114] system ver: 8.0, 
  11. orientaion: UIInterfaceOrientationPortraitUpsideDown, 
  12. window bounds: {{0, 0}, {480, 320}} 

iOS 7及之前的版本运行结果为:

  1. 2014-06-04 09:39:00.527 SviOS8[4380:70b] system ver: 7.0.3, 
  2. orientaion: UIInterfaceOrientationLandscapeRight, 
  3. window bounds: {{0, 0}, {320, 480}} 
  4. 2014-06-04 09:39:00.895 SviOS8[4380:70b] system ver: 7.0.3, 
  5. orientaion: UIInterfaceOrientationPortrait, 
  6. window bounds: {{0, 0}, {320, 480}} 
  7. 2014-06-04 09:39:01.225 SviOS8[4380:70b] system ver: 7.0.3, 
  8. orientaion: UIInterfaceOrientationLandscapeLeft, 
  9. window bounds: {{0, 0}, {320, 480}} 
  10. 2014-06-04 09:39:11.004 SviOS8[4380:70b] system ver: 7.0.3, 
  11. orientaion: UIInterfaceOrientationPortraitUpsideDown, 
  12. window bounds: {{0, 0}, {320, 480}} 

通过对比我们可以清晰的看到iOS 8中UIWindow在处理旋转时策略的变更,虽然会因为与之前的版本不同导致现有项目布局存在的bug,但是可以看到iOS 8中的处理方式更加符合我们的预期,在竖向的时候我们就获取到width < height, 在横向则是 width > height,这个符合所见即所得的原则。

题外话,不管是iOS 7还是之前的版本,以及***出的iOS 8,所有的ViewController的bounds都是正确的,所以只需要坚持一个原则“所有布局都是基于VC.view.bounds布局,那么你的App的显示就一切正常。”

当然如果你有任何View不受VC的管理,直接添加到window上,那么就悲剧了,请添加代码去单独支持。

好消息:所有基于iOS 7 SDK编译的程序,window的机制还遵循原来的机制,也就是说可以平滑过度到iOS系统,所有界面布局一切正常。不得不说苹果这一点做的真赞,不愧是一家伟大的公司。

2、安装iOS 8 beta版本注意事项

官方给出的注意事项地址: http://adcdownload.apple.com//wwdc_2014/ios_8_beta_wg4j9a/ios_beta_software_installation_guide.pdf

主要意思是:

1)升级后不可降级,so升级之前还是想清楚

2)做好备份工作,因为毕竟是beta版本,可能有些不稳定的地方,可能在升级过程中会丢失数据

3)支持设备:

iPhone 4s, iPhone 5, iPhone 5c, iPhone 5s, iPod touch (5th gen),
iPad 2, iPad with Retina display, iPad Air and iPad mini

4)目前只支持开发者预览

5)反馈问题地址如下: https://developer.apple.com/bug-reporting/

3、QR Code支持

Core Image framework (CoreImage.framework)新增了如下API:

  • 支持自定义imageKernels

  • 增加矩形检测和图片中二维码识别功能

详细文档: Core Image Reference Collection.

责任编辑:闫佳明 来源: cnblogs
相关推荐

2012-05-03 10:24:02

ApacheMINAJava

2010-03-05 17:25:07

sharepoint

2021-03-08 08:21:19

词云数据可视化大数据

2011-11-30 16:02:13

笔记本评测

2017-04-11 20:49:02

机器学习大数据数据分析

2017-05-04 21:15:30

Android分辨率

2014-12-16 15:10:32

APC BR1000G后备式UPS电源

2021-01-08 09:07:19

Scrapy框架爬虫

2012-02-24 10:48:56

语盒开源

2021-05-20 07:56:35

Bean容器Spring

2023-10-07 08:59:02

2022-07-04 23:24:28

sql优化监控

2018-01-01 23:02:56

2011-09-15 11:04:22

Windows 8平板

2023-04-20 17:41:38

开源清华

2011-10-13 10:08:51

iOS 5iOS

2022-06-08 21:13:49

iOSiOS 16

2011-04-26 09:13:15

webservice

2014-06-06 14:25:03

iOS 8SwiftWWDC2014

2014-12-12 10:25:21

Xcode 6iOS快速上手
点赞
收藏

51CTO技术栈公众号