Http://www.cocoachina.com/ios/20150714/12555.html
This article is translated by Iron Man-like Chingo (Weibo) from Apple's official document: Adopting multitasking enhancements on the ipad, which focuses on the multitasking capabilities of the ipad in iOS 9.
This document contains:
Part I: IOS 9 split-screen multitasking--Getting Started
Part II: IOS 9 Split-screen multitasking--slide over & Split view Quick Start
Part III: IOS 9 Split-screen multitasking-pip Quick Start
Important
This is a preliminary document for the API or development technology. Apple provides this information primarily to help you plan through the use of these technologies or programming interfaces with Apple products, which may change in the future, and the software mentioned in this article should be based on the final published operating system tests and final documentation. New versions of document information may be available in the future.
Multitasking in IOS 9 gives us more ways to enjoy the ipad and app.
Slide over: users can view and interact with the secondary application by bringing up a hover view on the right side of the screen (located on the left side of the screen in a right-to-left language environment).
Split view: renders two parallel apps that allow users to view, resize, and interact with each other.
pip in picture feature : Lets users hover over video in multiple apps, move video windows, and resize windows.
In the slide over feature, the full screen app is the main app. The app selected on slide over is the secondary app. The app on the left is the main app in Split view (in a left-to-right language environment) and the secondary app on the right.
If you follow Apple iOS 8 best practices recommendations, all of these new ways of interacting with apps, especially multitasking in iOS 9, are very simple and intuitive. Starting with Xcode 7, each iOS App template supports slide over and Split View by default.
From the developer's point of view, the biggest challenge is the management of resources.
Every iOS app, even those that don't use multitasking, needs to run well in iOS9. Now, even full-screen apps are not effectively leveraging the entire screen, CPU, memory, and other resources. For example, users can:
Adding a picture-in-picture window to the screen, regardless of what is displayed on the screen (including a full-screen app), the app that contains the video continues to run in the background. Pip from other apps increases the app's memory pressure while reducing the app's display frame rate.
Swipe slide over to use the secondary app. When it is visible, the secondary app runs in the foreground, increasing the app's memory pressure again, reducing the app's display frame rate.
Calling the keyboard from the secondary app with slide over will obscure part of the main app. Every iOS9 developer, or even a developer who has developed a full-screen app but never used keyboard, may want to respond to a keyboard notification as described in UIWindow Class reference.
To be able to participate effectively in this environment, IOS9 developers must carefully adjust the resource consumption of their apps. If an app consumes too much time per frame, the screen's refresh rate will be less than 60 fps. Under memory pressure, the system terminates the app that consumes the most memory.
To learn more about how to manage resources in iOS 9, see multitasking Mindset.
Understand the features of your app and look at your work
Consider the features of your app before deciding which multi-tasking enhancements you want to take and what you need to do.
Most apps should use slide over and Split View. From the user's point of view, an iOS 9 app does not support these two features and is a bit out of tune.
Multi-tasking is not supported if your app meets one of the following conditions:
A camera-centric app that uses the entire screen preview and captures the instant instantly as the main feature.
Apps that use full-screen screens, such as games using ipad sensors as part of the game's core manipulation.
In addition, Apple and your users want you to use slide over and Split View. For more information, see Slide over & Split View Quick Start.
If you do not use slide over and Split View, you need to add Uirequiresfullscreen key to the Info.plist file for your Xcode project, and set its Boolean value to Yes.
Note: do not use slide over and Split View to indicate that your app cannot appear in the slide over region, even though your app is running in a multi-tasking environment. Test your app on the hardware you want to support to make sure your app runs smoothly when other apps appear in slide over mode and in Pip mode, which plays video from a third app.
Pip is for apps that play video as the main feature. Pip is also best suited for medium to long time content playback.
Supports PIP, allowing your users to interact with your app or other apps while playing the video screen. To learn and use PIP, please read picture in picture Quick Start.
Transitions in the game scene, first boot, and similar content should not support PIP. You can select a given video to exit Pip as follows:?
For the Avplayerviewcontroller class, set the Allowspictureinpictureplayback property value to No.
For the Avplayerlayer class, do not instantiate a Avpictureinpicturecontroller object with your playback layer object
For the Wkwebview class, set its Allowspictureinpicturemediaplayback property to No (this property is available in future versions of iOS 9beta).
Note: If your app uses the Media Player framework to play a video, regardless of the MPMoviePlayerController or Mpmovieplayerviewcontroller class in its frame, You must migrate using Avkit or AV Foundation. Media player video playback is officially deprecated in iOS 9.
If your app plays an HTTP Live streaming (HLS) video, use meta data to optimize playback. Optimize the performance of your application under a variety of viewport window sizes by responding to stream-variant metadata labels. and to minimize battery consumption, the Content distribution network (CDNS) You use should also provide multiple stream variants and label each variant with the appropriate resolution label. For more information, see HTTP Live streaming Overview.
If your application presents content on a second physical screen, test the app's transitions.
In particular, you need to test use cases that transition from a minor app to a primary app. Only the main app is eligible for a second physical screen, so transitioning to the main app is a new scene where your app can receive uiscreendidconnectnotification notifications. Make sure your app helps users understand what's going on in the usage instance, which can be a bit odd when the content moves to the second screen.
Development environment
XCODE7 supports multi-tasking enhancements on ipad.
Use the new features in Xcode 7, emulators, and instruments:
Pre-configured support for slide over and Split View in each iOS app template. For example, include the Launchscreen.storyboard file and the pre-set Info.plist file. See: Xcode Overview
The storyboards in Interface Builder makes it easy to implement automatic layout constraints. See Auto Layout Guide and auto layout help.
The Interface Builder Preview Assistant gives you immediate view of how your layout fits into the different size classes in the slide over and split view scenes. See Size Classes Design Help and? Previewing Your Layout for Different localizations, iOS Devices, and iOS Versions.
The simulator in Xcode 7 lets you bring up slide over and Split View using the same gestures in real-world devices. You can use the simulator to test all slide over and split View layouts, as well as to test PIP. However, the emulator does not emulate the memory, CPU, GPU, disk I/O, or other resource characteristics of the iOS device for a real iOS device. For instructions on using the simulator, see Simulator User Guide.
Memory allocations, time Profiler, memory leak analysis Templates (Leaks profiling templates) in instrument allow you to monitor app behavior and resource usage. See: Instruments User Guide and Instruments Help.
XCODE7 provides a visual interface for full support of the resource catalog (asset catalog). Use resource catalogs, slices, and app icons for your visual resources. This is important for optimizing the memory of your app. See Asset Catalog Help. You can also use the resource directory programmatically, see Uiimageasset Class Reference?.
To test the memory, CPU, GPU, and all hardware-related performance, test the app on the hardware you want to support. To test your app on an iOS device, you must be a member of the iOS developer program. See Managing Accounts in the APP distribution guide.
In IOS9, the following models of ipad support multi-tasking enhancements.
Multi-tasking thinking mode
To succeed on an ipad that supports iOS 9, your app must perform well on device resources, whether it's on the system or other apps on the device.
When your app is running in the foreground, other apps may run alongside it, or you can play PIP video, and the app that holds it runs in the background.
Before iOS9, you can maintain an excellent experience with any available CPU, GPU, memory, I/O, and hardware resources. In iOS 9, these will change. How the app effectively leverages resources becomes a key issue, so the user's ipad experience is smooth and responsive.
To get the best user experience, the system tightly manages resource consumption and terminates apps that use more than the system quota resource.
Most of the work you do with multitasking on your ipad is likely to be a best practice for resource management. The first step:
Test your app with instrument to make sure it has no memory leaks, no unlimited memory growth, or block the main thread.
Using the protocol method of applying state transitions, discard unnecessary view controllers, views, resources, and data caches when your app moves to the background.
Test your app on each supported device and use resource-intensive apps such as the map app to set up satellite views and perform overpass image animations. Test your app as a major app and a secondary app, to make sure your app and map app respond quickly in both cases.
In iOS 9, it is no longer appropriate to consider from the screen's interface orientation. The app can be used on ipad to fit the compact size class or regular size class in the horizontal direction, and the size changes independently of the orientation of the interface. Instead, use the trait collections and size Classes, with the Uicontentcontainer and uitraitenvironment protocols, see slide over and Split View Quick Start is described.
Also in iOS 9, it's no longer appropriate to use the screen's range limits to determine the visible area of your app, but to use the scope of your app's window. Be aware that the scope of your app should be manipulative. You can't set the app's range limits or prevent it from changing.
Although auto layout is not required for the best iOS 9 app, it is easier to do so. Automatic layout provides the benefits of performance and helps you match the best practices that Apple describes in IOS Human Interface guidelines. Simply put, Auto layout helps your content show up in the right place and helps in future iterations of your app. You can use auto layout over and over again, one layout at a time. At a minimum, your Launchscreen.storyboard file must use Auto Layout. Throughout your app, use storyboards to help your view adapt to changes in view size when users open and use your app in different situations.
IOS 9 Split-screen multitasking: Getting Started (Chinese version)