{"id":565,"date":"2012-09-26T16:27:36","date_gmt":"2012-09-26T08:27:36","guid":{"rendered":"http:\/\/xujiwei.com\/blog\/?p=565"},"modified":"2016-12-27T01:38:09","modified_gmt":"2016-12-26T17:38:09","slug":"migrate-ios-app-for-iphone-5-and-ios-6","status":"publish","type":"post","link":"https:\/\/xujiwei.com\/blog\/2012\/09\/migrate-ios-app-for-iphone-5-and-ios-6\/","title":{"rendered":"[Tips] \u9002\u914d iOS App \u5230 iPhone 5 \u548c iOS 6"},"content":{"rendered":"<p>iPhone 5 \u548c iOS 6 \u6b63\u5f0f\u53d1\u5e03\u540e\uff0ciOS \u5f00\u53d1\u8005\u4eec\u5c31\u8981\u5f00\u59cb\u505a iPhone 5 \u548c iOS 6 \u7684\u9002\u914d\u5de5\u4f5c\u4e86 :)<\/p>\n<p>\u5728\u8fc1\u79fb\u6211\u81ea\u5df1\u7684\u51e0\u4e2a iOS App \u8fc7\u7a0b\u4e2d\uff0c\u53d1\u73b0\u4e86\u8001\u7684 Xcode \u5de5\u7a0b\u4ee3\u7801\u5728 iOS 6 \u4e2d\u65e0\u6cd5\u54cd\u5e94\u5c4f\u5e55\u65cb\u8f6c\u7684\u95ee\u9898\uff0c\u5728\u8fd9\u91cc\u8bb0\u5f55\u4e00\u4e0b\u3002\u987a\u4fbf\u8bb0\u5f55\u4e00\u4e0b\u600e\u6837\u9002\u914d iOS App \u5230 iPhone 5 \u7ed9\u8fd8\u4e0d\u77e5\u9053\u600e\u4e48\u505a\u7684\u670b\u53cb\u4eec\u3002<\/p>\n<h2>\u9002\u914d iPhone 5 \u7684 4 \u5bf8\u5c4f\u5e55<\/h2>\n<p class=\"alignright\" style=\"text-align:center\"><img loading=\"lazy\" src=\"http:\/\/xujiwei.com\/blog\/wp-content\/uploads\/2012\/09\/iOS_App_LetterBox.png\" alt=\"\" title=\"iOS_App_LetterBox\" width=\"207\" height=\"417\" class=\"size-full wp-image-567\" \/><br \/><small><em>iOS App LetterBox Mode<\/em><\/small><\/p>\n<p>iPhone 5 \u7684\u5c4f\u5e55\u5206\u8fa8\u7387\u4e3a 640x1136\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u8001\u7684 iOS App \u4f1a\u4ee5\u4e0a\u4e0b\u52a0\u4e24\u6761\u9ed1\u8fb9\u7684\u6a21\u5f0f\u6765\u8fd0\u884c\uff0c\u7a0b\u5e8f\u5b9e\u9645\u5360\u7528\u7684\u5206\u8fa8\u7387\u8fd8\u662f 640x960\uff0c\u4fdd\u8bc1\u4e86\u539f\u6709\u7684 iOS App \u5728\u4e0d\u4fee\u6539\u7684\u60c5\u51b5\u4e0b\u4e5f\u53ef\u4ee5\u6b63\u5e38\u8fd0\u884c\u3002<\/p>\n<p>\u5982\u679c\u9700\u8981\u9002\u914d iPhone 5 \u7684 4 \u5bf8\u5c4f\u5e55\uff0c\u662f\u4e00\u4ef6\u5f88\u7b80\u5355\u7684\u4e8b\uff0c\u53ea\u9700\u8981\u6dfb\u52a0\u4e00\u5f20\u5bf9\u5e94 iPhone 5 \u542f\u52a8\u56fe\u7247\u5373\u53ef\u3002<\/p>\n<p>iPhone 5 \u7684\u5206\u8fa8\u7387\u4e3a 640x1136\uff0c\u6240\u4ee5\u53ea\u9700\u8981\u6dfb\u52a0\u4e00\u5f20\u5206\u8fa8\u7387\u4e3a 640x1136 \u7684\u542f\u52a8\u56fe\u7247\u5230 iOS App \u5de5\u7a0b\u5373\u53ef\u3002\u542f\u52a8\u56fe\u7247\u9700\u8981\u547d\u540d\u4e3a Default-568h@2x.png\uff0c\u56e0\u4e3a iPhone 5 \u6ca1\u6709\u975e Retina \u5c4f\u5e55\u7684\u578b\u53f7\uff0c\u6240\u4ee5\u4e0d\u9700\u8981 Default-568h.png \u8fd9\u6837\u4e00\u4e2a\u6587\u4ef6\u4e86\u3002<\/p>\n<p>\u6dfb\u52a0\u4e86\u5bf9\u5e94 iPhone 5 \u5206\u8fa8\u7387\u7684\u542f\u52a8\u56fe\u7247\u540e\uff0ciOS App \u5c31\u4f1a\u4ee5 640x1136 \u7684\u5206\u8fa8\u7387\u8fd0\u884c\u4e86\u3002<\/p>\n<p>\u5f53\u7136\u4e86\uff0c\u5982\u679c iOS App \u91cc\u5728\u8ba1\u7b97 view \u7684 frame \u65f6\uff0c\u4f7f\u7528\u4e86\u56fa\u5b9a\u7684 320x480 \u6765\u8ba1\u7b97\u7684\u8bdd\uff0c\u5728\u663e\u793a\u65f6\u5c31\u4f1a\u6709\u4e00\u4e9b\u95ee\u9898\uff0c\u8fd9\u65f6\u5019\u5c31\u9700\u8981\u52a8\u6001\u6839\u636e view \u7684 frame \u5927\u5c0f\u53bb\u8ba1\u7b97\uff0c\u800c\u4e0d\u662f\u4f7f\u7528 Hard Code\u3002<\/p>\n<p>\u53e6\u5916\uff0c\u4e5f\u53ef\u4ee5\u7075\u6d3b\u4f7f\u7528 autoresizingMask\uff0c\u8fd9\u6837\u5728\u672a\u6765 iPhone \u53c8\u6709\u5176\u4ed6\u5206\u8fa8\u7387\uff0c\u53c8\u6216\u8005\u51fa\u73b0\u4e86 iPad mini \u7684\u65f6\u5019\u66f4\u65b9\u4fbf\u5904\u7406\u3002<\/p>\n<h2>\u89e3\u51b3\u65e7\u7684 iOS App \u5728 iOS 6 \u4e2d\u65e0\u6cd5\u968f\u5c4f\u5e55\u65cb\u8f6c\u7684\u95ee\u9898<\/h2>\n<p>\u5982\u679c\u4f60\u7684 iOS App \u652f\u6301\u968f\u5c4f\u5e55\u65cb\u8f6c\u800c\u65cb\u8f6c\uff0c\u4f46\u662f\u5230\u4e86 iOS 6 \u4e2d\uff0c\u53d1\u73b0\u8fd9\u4e2a\u529f\u80fd\u4e0d\u751f\u6548\u4e86\uff0c\u90a3\u4e48\u5c31\u8981\u68c0\u67e5\u4e00\u4e0b\u662f\u4e0d\u662f\u56e0\u4e3a\u65e7\u7248\u672c\u7684 Xcode \u521b\u5efa\u5de5\u7a0b\u7684\u539f\u56e0\u3002<\/p>\n<p>\u4f46\u662f\u5728 iOS SDK Release Notes for iOS 6.0 \u4e2d\u7684 UIKit \u4e00\u8282\u4e2d\u8bf4\u5230\u201c<strong>Autorotation is changing in iOS 6. In iOS 6, the shouldAutorotateToInterfaceOrientation: method of UIViewController is deprecated. In its place, you should use the supportedInterfaceOrientationsForWindow: and shouldAutorotate methods.<\/strong>\u201d\uff0c\u5e76\u4e14\u8be6\u7ec6\u89e3\u91ca\u4e2d\u4e5f\u8bf4\u660e\u4e86 iOS 6 \u4e2d\u7684\u6539\u52a8\uff1a<\/p>\n<blockquote><p>\n  More responsibility is moving to the app and the app delegate. Now, iOS containers (such as UINavigationController) do not consult their children to determine whether they should autorotate. By default, an app and a view controller\u2019s supported interface orientations are set to UIInterfaceOrientationMaskAll for the iPad idiom and UIInterfaceOrientationMaskAllButUpsideDown for the iPhone idiom.<\/p>\n<p>  A view controller\u2019s supported interface orientations can change over time\u2014even an app\u2019s supported interface orientations can change over time. <strong>The system asks the top-most full-screen view controller (typically the root view controller) for its supported interface orientations whenever the device rotates or whenever a view controller is presented with the full-screen modal presentation style.<\/strong> Moreover, the supported orientations are retrieved only if this view controller returns YES from its shouldAutorotate method. The system intersects the view controller\u2019s supported orientations with the app\u2019s supported orientations (as determined by the Info.plist file or the app delegate\u2019s application:supportedInterfaceOrientationsForWindow: method) to determine whether to rotate.<\/p>\n<p>  The system determines whether an orientation is supported by intersecting the value returned by the app\u2019s supportedInterfaceOrientationsForWindow: method with the value returned by the supportedInterfaceOrientations method of the top-most full-screen controller.<\/p>\n<p>  The setStatusBarOrientation:animated: method is not deprecated outright. It now works only if the supportedInterfaceOrientations method of the top-most full-screen view controller returns 0. This makes the caller responsible for ensuring that the status bar orientation is consistent.<\/p>\n<p>  For compatibility, view controllers that still implement the shouldAutorotateToInterfaceOrientation: method do not get the new autorotation behaviors. (In other words, they do not fall back to using the app, app delegate, or Info.plist file to determine the supported orientations.) Instead, the shouldAutorotateToInterfaceOrientation: method is used to synthesize the information that would be returned by the supportedInterfaceOrientations method.\n<\/p><\/blockquote>\n<p>\u8bf4\u660e\u4e2d\u63d0\u5230\uff0c\u5728 iOS 6 \u4e2d\u7cfb\u7edf\u4f1a\u901a\u8fc7\u67e5\u8be2 rootViewController \u6765\u5224\u65ad\u662f\u5426\u53ef\u4ee5\u65cb\u8f6c\u89c6\u56fe\uff0c\u4f46\u662f\u5728\u4ee5\u524d\uff0c\u4f7f\u7528 Xcode \u521b\u5efa\u4e00\u4e2a\u5de5\u7a0b\u65f6\uff0c\u901a\u5e38\u4f1a\u6709\u4ee5\u4e0b\u4ee3\u7801\u6765\u663e\u793a\u4e3b\u7a97\u53e3\uff1a<\/p>\n<pre lang=\"objc\">\n- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    \n    \/\/ Add the tab bar controller's view to the window and display.\n    [self.window addSubview:tabBarController.view];\n    [self.window makeKeyAndVisible];\n\n    return YES;\n}\n<\/pre>\n<p>\u5728\u8fd9\u91cc\uff0c\u5e76\u6ca1\u6709\u8bbe\u7f6e self.window \u7684 rootViewController\uff0c\u800c\u4e14\u5728 MainWindow.xib \u4e2d\uff0c\u4e5f\u6ca1\u5728\u8fde\u63a5 window \u7684 rootViewController \u5230\u9ed8\u8ba4\u7684 UITabBarController\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u6211\u4eec\u6709\u4e24\u79cd\u65b9\u6cd5\u6765\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff1a<\/p>\n<p><strong>1. \u5728\u4ee3\u7801\u4e2d\u8bbe\u7f6e rootViewController<\/strong><\/p>\n<pre lang=\"objc\">\n- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    \n    \/\/ Add the tab bar controller's view to the window and display.\n    self.window.rootViewController = tabBarController;\n    [self.window addSubview:tabBarController.view];\n    [self.window makeKeyAndVisible];\n\n    return YES;\n}\n<\/pre>\n<p><strong>2. \u5728 MainWindow.xib \u4e2d\u8fde\u63a5 window \u7684 rootViewController<\/strong><\/p>\n<p><img loading=\"lazy\" src=\"http:\/\/xujiwei.com\/blog\/wp-content\/uploads\/2012\/09\/ConnectRootViewController.png\" alt=\"\" title=\"ConnectRootViewController\" width=\"550\" height=\"361\" class=\"size-full wp-image-568\" srcset=\"https:\/\/xujiwei.com\/blog\/wp-content\/uploads\/2012\/09\/ConnectRootViewController.png 550w, https:\/\/xujiwei.com\/blog\/wp-content\/uploads\/2012\/09\/ConnectRootViewController-300x196.png 300w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/p>\n<p>\u4e24\u79cd\u65b9\u6cd5\u4efb\u610f\u9009\u62e9\u4e00\u79cd\u5c31\u884c\u4e86\u3002<\/p>\n<p>\u5f53\u7136\u4f7f\u7528\u65b0\u7248\u672c Xcode \u521b\u5efa\u7684\u5de5\u7a0b\u5e94\u8be5\u662f\u6ca1\u95ee\u9898\u7684\uff0c\u800c\u4e14\u65b0\u7248\u672c Xcode \u7684\u5de5\u7a0b\u6a21\u677f\u901a\u5e38\u4f1a\u4f7f\u7528\u4ee3\u7801\u6765\u521b\u5efa rootViewController\uff0c\u800c\u4e14\u9ed8\u8ba4\u4e5f\u4e0d\u518d\u751f\u6210 MainWindow.xib\u3002<\/p>\n<h2>\u53c2\u8003\u8d44\u6599<\/h2>\n<ol>\n<li><a href=\"https:\/\/developer.apple.com\/library\/ios\/#releasenotes\/General\/RN-iOSSDK-6_0\/_index.html\">iOS SDK Release Notes for iOS 6<\/a><\/li>\n<\/ol>\n<p>---EOF---<\/p>\n","protected":false},"excerpt":{"rendered":"<p>iPhone 5 \u548c iOS 6 \u6b63\u5f0f\u53d1\u5e03\u540e\uff0ciOS \u5f00\u53d1\u8005\u4eec\u5c31\u8981\u5f00\u59cb\u505a iPh &hellip;<\/p>\n<p class=\"read-more\"><a href=\"https:\/\/xujiwei.com\/blog\/2012\/09\/migrate-ios-app-for-iphone-5-and-ios-6\/\">\u7ee7\u7eed\u9605\u8bfb &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[168],"tags":[154,217,218],"_links":{"self":[{"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/posts\/565"}],"collection":[{"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/comments?post=565"}],"version-history":[{"count":0,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/posts\/565\/revisions"}],"wp:attachment":[{"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/media?parent=565"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/categories?post=565"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/tags?post=565"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}