IOS 7过渡之---支持IOS 6

来源:互联网 发布:数据分析职业规划 编辑:程序博客网 时间:2024/05/19 13:20

Supporting iOS 6

If business reasons require you to continue supporting iOS 6 or earlier, you need to choose the most practical way to update the app for iOS 7. The techniques you choose can differ, but the overall advice remains the same: Focus on redesigning the app for iOS 7 first. Then, bring the changes to the iOS 6 version as appropriate.

如果因为商业原因需要你继续支持IOS6或者更早,你需要选择最实用的方式来为APP做IOS7更新。你选择技术可以不一样,但是最重要的建议一条是:专注为IOS7重新设计优先,然后恰当的改变IOS 6版本。

NOTE

On a device running iOS 7, all of the system UI—such as alerts and notifications—uses the iOS 7 appearance, even if your app is currently using an earlier appearance.

注:

在任意设备上操作系统是IOS 7的话,所有的系统UI,包括警告框和通知,都是用IOS 7的风格展示,即使你的应用当前运行的是老的风格。

Using Interface Builder to Support Multiple App Versions

使用Interface Builder 来支持多个应用版本。

Interface Builder in Xcode 5 includes new features that help you transition an app to iOS 7 while continuing to support earlier versions.

Interface Builder in Xcode 5 包含了新的功能,当你需要继续支持老版本时,可以帮助你把应用版本转换到IOS 7。

Get a preview of how the UI updates you make affect an earlier version. Using the assistant editor, you can make changes to an iOS 7 storyboard or xib file on the canvas and simultaneously see how those changes look in the iOS 6 version of the file.

我们来预览一下新的设计在老版本里面是怎么展现情况的。使用帮助编辑器.....下面就不翻译了哦,按步骤操作就知道了。

Follow these steps to preview an earlier storyboard or xib file:

  1. While viewing the iOS 7 storyboard or xib file on the canvas, open the assistant editor.

  2. Open the Assistant pop-up menu. (The Assistant pop-up menu is the first item to the right of the back and forward arrows in the assistant editor jump bar.)

  3. In the menu, scroll to the Preview item and choose the storyboard or xib file.

    image: ../Art/assistant_preview_2x.png

Toggle between viewing app UI in iOS 7 and iOS 6.1 or earlier. If your app needs to support iOS 6.1 or earlier, use this feature to make sure the UI looks correct in all versions of the app.

Follow these steps to switch between two versions of the UI:

  1. Open the File inspector in Interface Builder.

  2. Open the “View as” menu.

  3. Choose the version of the UI you want to view.

For more information about new Interface Builder features in Xcode 5, see What's New in Xcode.

Supporting Two Versions of a Standard App

为标准应用支持两个版本

If both versions of a standard app should have a similar layout, use Auto Layout to create a UI that works correctly in both versions of iOS. To support multiple versions of iOS, specify a single set of constraints that Auto Layout can use to adjust the views and controls in the storyboard or xib files (to learn more about constraints, see “Constraints Express Relationships Between Views”).

如果标准应用的两个版本需要有相同的布局,使用自动布局来创建UI可以正常的运行在两个版本。为了支持IOS多版本,设置一些约束集,自动布局可以在storyboard或者XIB文件里修正视图和控件。想知道更多关于这个约束集的,请看: “Constraints Express Relationships Between Views

If both versions of a standard app should have a similar layout and you’re not using Auto Layout, use offsets. To use offsets, first update the UI for iOS 7. Next, specify values that define the origin, height, and width of each element in the earlier UI as offsets from the element’s new position in the iOS 7 UI.

如果标准应用的两版本使用了相同的布局但是你没有使用自动布局,使用offsets。 为使用offsets,首先要为IOS7升级UI。然后,在老版UI里面指定每个元素的顶点、宽高为offsets (在 iOS 7里面新的元素位置)

To learn more about Auto Layout, see Cocoa Auto Layout Guide.

要了解更多自动布局,请看 Cocoa Auto Layout Guide.

Managing Multiple Images in a Hybrid App

在混合应用里面管理各种图片

Hybrid apps often include custom image assets, such as bar button icons, and background views for bars or other controls. Apps can use one or more asset catalogs to manage these resources. (To learn more about asset catalogs, see Asset Catalog Help .)

混合应用经常包含了图片资源,比如BAR按钮上的图标,背景视图或者其他控件。应用可以使用一个或者多个资源类别来管理这些资源。(要学习资源类别,请看:see Asset Catalog Help

NOTE

An asset catalog contains resources that are displayed within an app; an asset catalog doesn’t hold the app icon, launch image, or any other image that an outside process needs to access.

注:

一个资源类别包含了显示在应用内的资源文件;一个资源类别不包含应用图标,加载图片,或者其他存取权限之外的进程里面的图片。

In a hybrid app that must support multiple versions of iOS, you manage the images yourself. Images that differ depending on an app’s version should have unique names; otherwise, you can use the same image in both versions.

在必须支持多IOS版本的混合应用里面,你需要自己管理图片。使用哪种图片,依赖于应用的版本,图片需要有唯一的名字;否则,你会在两个版本里面载入相同的图片了。

If your storyboard or xib file contains an embedded image, consider creating an outlet to the image view and loading the appropriate resource as needed. To learn how to load different assets in code, see “Loading Resources Conditionally”.

如果在你的storyboard 或者xib文件里面嵌入了图片,考虑创建一个图片视图做外部引用并且在合适的时机加载资源,如果有必要的话。学习如何加载不同的资源,代码请见 “Loading Resources Conditionally”.



Loading Resources Conditionally

加载资源的条件

In some cases, you need to determine the iOS version your app is currently running in so you can respond appropriately in code. For example, if different versions of an app use significantly different layouts, you can load different storyboard or xib files for each version. You may also need to use different code paths to handle API differences, such using barTintColor instead of tintColor to tint a bar’s background.

在某些情况下,你需要判断当前你应用在运行的IOS系统版本,然后你的代码可以作出恰当的响应。比如,应用在不同操作系统下使用明显不同的布局时,你可以为不同的版本加载不同 storyboard或者xib文件。你可能还需要用不同的代码方式去处理API的差异,比如用barTintColor替换tintColor 来为BAR的背景着色。  

If you need to load different resources for different app versions—and you currently identify a storyboard or xib file in your Info.plist file—you can instead check the system version and load the appropriate resource in application:didFinishLaunchingWithOptions:.

如果你需要为不同的应用加载资源,你当前需要定义一个STOREBOARD或者XIB文件在你的INFO.PLIST文件里面。你可以在application:didFinishLaunchingWithOptions:.用检查系统版本并且加载不同的资源文件。

One way to find out whether an app is currently running in iOS 7 or earlier is to write a macro that checks the system version. The code below shows a way to check the system version and store the result so you can refer to it whenever you need to conditionally load resources or use different APIs.

一种检查你的当前在跑的是IOS 7还是更早的操作系统的方法:写一个宏来检查系统版本。下面的代码展示了这样ige方法,你可以根据这个来判断加载什么资源或者用什么不同的API 。

  1. NSUInteger DeviceSystemMajorVersion();
  2. NSUInteger DeviceSystemMajorVersion() {
  3. static NSUInteger _deviceSystemMajorVersion = -1;
  4. static dispatch_once_t onceToken;
  5. dispatch_once(&onceToken, ^{
  6. _deviceSystemMajorVersion = [[[[[UIDevice currentDevice] systemVersion] componentsSeparatedByString:@"."] objectAtIndex:0] intValue];
  7. });
  8. return _deviceSystemMajorVersion;
  9. }
  10. #define MY_MACRO_NAME (DeviceSystemMajorVersion() < 7)
原创粉丝点击