iOS 8 初上手 牛刀小試
1、UIWindow的bounds發(fā)生變化(Window本身發(fā)生了旋轉(zhuǎn))
iOS 7之前Window的bounds不會隨著方向而變化,但是到了iOS 8以后,隨著設(shè)備方向的旋轉(zhuǎn),window.bounds.size.width和window.bounds.size.height也會相應(yīng)發(fā)生變化。
做個很簡單的測試,代碼如下:
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
- // Override point for customization after application launch.
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(orientationChanged:)
- name:UIDeviceOrientationDidChangeNotification
- object:nil];
- return YES;
- }
- - (void)orientationChanged:(NSNotification*)noti {
- UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
- NSString *orientationDes = nil;
- switch (orientation) {
- case UIDeviceOrientationLandscapeLeft:
- orientationDes = @"UIInterfaceOrientationLandscapeRight";
- break;
- case UIDeviceOrientationLandscapeRight:
- orientationDes = @"UIInterfaceOrientationLandscapeLeft";
- break;
- case UIDeviceOrientationPortrait:
- orientationDes = @"UIInterfaceOrientationPortrait";
- break;
- case UIDeviceOrientationPortraitUpsideDown:
- orientationDes = @"UIInterfaceOrientationPortraitUpsideDown";
- break;
- default:
- orientationDes = @"";
- break;
- }
- NSLog(@"system ver: %@, \rorientaion: %@, \rwindow bounds: %@",
- [UIDevice currentDevice].systemVersion,
- orientationDes,
- NSStringFromCGRect(self.window.bounds));
- }
示例代碼很簡單,新建一個工程,然后在delegate中直接添加以上代碼即可。
iOS 8上運行結(jié)果為:
- 2014-06-04 09:26:32.016 SviOS8[4143:61114] system ver: 8.0,
- orientaion: UIInterfaceOrientationLandscapeRight,
- window bounds: {{0, 0}, {320, 480}}
- 2014-06-04 09:26:34.788 SviOS8[4143:61114] system ver: 8.0,
- orientaion: UIInterfaceOrientationPortrait,
- window bounds: {{0, 0}, {480, 320}}
- 2014-06-04 09:26:35.791 SviOS8[4143:61114] system ver: 8.0,
- orientaion: UIInterfaceOrientationLandscapeLeft,
- window bounds: {{0, 0}, {320, 480}}
- 2014-06-04 09:26:47.468 SviOS8[4143:61114] system ver: 8.0,
- orientaion: UIInterfaceOrientationPortraitUpsideDown,
- window bounds: {{0, 0}, {480, 320}}
iOS 7及之前的版本運行結(jié)果為:
- 2014-06-04 09:39:00.527 SviOS8[4380:70b] system ver: 7.0.3,
- orientaion: UIInterfaceOrientationLandscapeRight,
- window bounds: {{0, 0}, {320, 480}}
- 2014-06-04 09:39:00.895 SviOS8[4380:70b] system ver: 7.0.3,
- orientaion: UIInterfaceOrientationPortrait,
- window bounds: {{0, 0}, {320, 480}}
- 2014-06-04 09:39:01.225 SviOS8[4380:70b] system ver: 7.0.3,
- orientaion: UIInterfaceOrientationLandscapeLeft,
- window bounds: {{0, 0}, {320, 480}}
- 2014-06-04 09:39:11.004 SviOS8[4380:70b] system ver: 7.0.3,
- orientaion: UIInterfaceOrientationPortraitUpsideDown,
- window bounds: {{0, 0}, {320, 480}}
通過對比我們可以清晰的看到iOS 8中UIWindow在處理旋轉(zhuǎn)時策略的變更,雖然會因為與之前的版本不同導(dǎo)致現(xiàn)有項目布局存在的bug,但是可以看到iOS 8中的處理方式更加符合我們的預(yù)期,在豎向的時候我們就獲取到width < height, 在橫向則是 width > height,這個符合所見即所得的原則。
題外話,不管是iOS 7還是之前的版本,以及***出的iOS 8,所有的ViewController的bounds都是正確的,所以只需要堅持一個原則“所有布局都是基于VC.view.bounds布局,那么你的App的顯示就一切正常。”
當(dāng)然如果你有任何View不受VC的管理,直接添加到window上,那么就悲劇了,請?zhí)砑哟a去單獨支持。
好消息:所有基于iOS 7 SDK編譯的程序,window的機制還遵循原來的機制,也就是說可以平滑過度到iOS系統(tǒng),所有界面布局一切正常。不得不說蘋果這一點做的真贊,不愧是一家偉大的公司。
2、安裝iOS 8 beta版本注意事項
官方給出的注意事項地址: http://adcdownload.apple.com//wwdc_2014/ios_8_beta_wg4j9a/ios_beta_software_installation_guide.pdf
主要意思是:
1)升級后不可降級,so升級之前還是想清楚
2)做好備份工作,因為畢竟是beta版本,可能有些不穩(wěn)定的地方,可能在升級過程中會丟失數(shù)據(jù)
3)支持設(shè)備:
iPhone 4s, iPhone 5, iPhone 5c, iPhone 5s, iPod touch (5th gen),
iPad 2, iPad with Retina display, iPad Air and iPad mini
4)目前只支持開發(fā)者預(yù)覽
5)反饋問題地址如下: https://developer.apple.com/bug-reporting/
3、QR Code支持
Core Image framework (CoreImage.framework)新增了如下API:
-
支持自定義imageKernels
-
增加矩形檢測和圖片中二維碼識別功能