Highlights of iOS 9 multi-task screen splitting

Source: Internet
Author: User
Tags windows surface

Highlights of iOS 9 multi-task screen splitting

IOS 9 multi-task Overview

The most striking new feature in iOS 9 is multitasking. Similar plug-ins have appeared in jailbreak development a long time ago. For example, the Windows Surface series also has the features of split-screen multitasking, allows users to use two or more apps at the same time. Similar features are also added in iOS 9. There are three forms of multi-task in iOS 9: Temporary appearance and interactive Slide Over. The Split View of the two apps can be operated simultaneously on the Split View ), and the Picture in Picture mode, which can still be played by other apps.

In the multi-task documentation, Apple explicitly states:

Most APPs must adapt to Slide Over and Split View

This is exactly one of the core features of iOS 9 and what you expect. On the other hand, supporting multitasking also increases the possibility that your users can open and use your app. However, there is a limit on multitasking, that is, on iPad devices that can install iOS 9, only the most powerful iPad Air 2 and later models support the split view mode, other models, such as iPad mini 2, iPad mini 3, and iPad Air, can only be slide-covered or draw-in-picture. To a certain extent, this should be made based on the considerations of mobile device resources and performance constraints. After all, multi-tasking can make sense only when a good user experience is guaranteed.

For developers, although multiple la s seem complicated, it is not very difficult to adapt their iPad apps to multiple tasks if they keep up with Apple's technical pace. Because the layout adopted by the sliding coverage mode and the split view mode is actually the layout of the Compact Width, and this concept is the UI Layout Method Based on screen features introduced on WWDC14. If you are already using this layout method, you can say that the support for the multi-task view is automatically completed. However, if you have never used or even heard of this layout method, a last year's Note may help you get a preliminary understanding of it, in the next section, I will review related concepts and basic usage a little bit.

Adaptive UI Review

Adaptive UI is a concept proposed by Apple in iOS 8. Before that, if we want to develop apps for both the iPhone and iPad, we may write a lot of device-determined code, such:

 
 
  1. If UI_USER_INTERFACE_IDIOM () =. Pad {
  2. // The device is iPad
  3. }
  4.  
  5. In addition, if we want to adapt both horizontally and vertically, we need code similar to this:
  6.  
  7. If UIInterfaceOrientationIsPortrait (orientation ){
  8. // The screen is a vertical screen
  9. }

These judgments and branches are not only difficult to write but also difficult to adapt to development. Since iOS 8, developers should not rely on such devices for UI adaptation, but should instead use the new Size Class system. Apple designs a combination of Regular and Compact based on the size of its mobile devices. For example, the width of the iPhone is Compact, the height is Regular, the width of the iPhone 6 Plus is Regular, and the height is Compact, while the height and width of other iPhones on the horizontal screen are Compact; the width and height of the iPad are Regular regardless of the model and direction. Shows the Size Class of an existing device:

With the idea of developing a Size Class, we no longer care about the model or Size of a specific device, but show the content based on the characteristics of a specific Size Class. With the Regular width, We can display more content horizontally, for example, displaying both Master and Detail View Controller. Similarly, we should not care about device rotation, but the change of Size Class. During development, if Interface Builder is used, you should configure appropriate constraints and la s for different Size classes when creating the UI, which is sufficient in most cases. If you use code, the UITraitCollection Class will be the key to using and operating the Size Class. We can set a proper layout based on the traitCollection attribute of the UIViewController currently in work, and make a correct response to the UI layout when calling-willTransitionToTraitCollection: callback: And-viewWillTransitionToSize: withTransitionCoordinator.

Although it is not theoretically feasible, it is a very painful thing to use pure hand writing to operate Size Class. We should try to use IB to reduce the workload, accelerate development efficiency.

Multi-task adaptation in iPad

For multitasking in iOS 9, the size of the newly opened app will be 1/3 of the device size when sliding overwrites and splits the initial position of the view. However, this proportion is not important. We need to remember that the newly opened app will run under the Size Class of Compact Width and Regular Height. That is to say, if your iPad app uses the Size Class for layout and supports the iPhone portrait screen, congratulations, you only need to switch to the iOS 9 SDK and re-compile your app, that's it.

This article does not focus on how to develop an Adaptive UI app. If you have missed a course last year and do not know much about it, this tutorial may help you quickly understand and master the content. If you want to get started and see how multitasking works in iOS 9, you can create a Master-Detail Application and install it on the iPad simulator. The template project of Master-Detail sets up a framework that fits the Size Class well, so that the project can perform well on any device. You can also observe its performance on iOS 9 iPad.

However, not all apps should adapt to multiple tasks. For example, a game that requires full screen access is a typical example. If you do not want your app to be used as a multi-task sub-app, you can add UIRequiresFullScreen in Info. plist and set it to true.

Easy enough? Yes. To adapt to the multi-tasking of the iPad, all you need to do is develop a universal platform-wide app according to the standard process. That's all.

Use the iOS 9 SDK to build your app;

Supports all directions and corresponding Size Class;

Use the launch storyboard as the app startup page.

Although there are not many things worth mentioning, there are still some small details that need attention.

Some noteworthy small details

In the past, there was no such thing that the app would share the screen with another app at the front end. Therefore, UIScreen. bounds and the UIWindow. bounds in the main window are basically synonyms. However, in the multitasking era, the UIWindow may only have 1/3 or 1/2 screens. If you use it in your previous app to define your view, it is necessary to perform special processing for multiple tasks. However, although the sliding overwrite and split views are displayed on the right side, the origin of their windows is still (0, 0), which makes it easier for us to define the view.

The second detail is that the Size Class of the iPad UI will change. In the past, both vertical and horizontal, the Size of the iPad screen was always long and wide and Regular. However, in iOS 9, the situation is different. Your app may be opened as an additional app in multi-task mode, it may be dragged to the full screen app during multiple tasks (the Size Class will change from the width of Compact to Regular ), even if your app is used as the main app, it will become a Compact-wide app by dragging the app:

In other words, you do not know whether your app's Size Class will change or when it will change. This is the result of user operations. Therefore, we must fully consider this point during development, and strive to provide users with good results when the size changes. It is not necessary to design and adjust the UI Based on the screen size. In addition, you should pay attention to the use at the right time.TransitionCoordinatorOf-AnimateAlongsideTransition:To make the switch more natural.

Multi-task brings the possibility of multiple apps running on the same platform, so your apps will certainly be running together with other apps. When developing a mobile application, you must never forget the limitations of the device platform. Compared with desktop devices, mobile terminals only have limited memory, while two or even three apps run at the front end at the same time, we need to carefully design the memory usage. Generally, developers should rationally allocate Memory and listen to Memory Warning to release cache and unnecessary view controllers, so as to avoid circular reference and so on. This should be a basic skill in daily development.

The last detail is a perfect demand. In iOS 9, multiple tasks also use App Switcher to switch between apps. Therefore, when your app is switched to the background, the system will save the current status of your app for later display. Your app may be used as a full-screen Regular app or Compact layout, so the system will save two copies in sequence. Users may disable your app in full screen mode, and then enable your app as an additional app by multitasking, in this case, it is best to ensure that the App Switcher is consistent with the user's view after the app is opened to get the best experience. This may not be a big problem, but it is also necessary to pursue the ultimate user experience. For apps that contain sensitive user data that require fuzzy processing, you must also process both la S.

Picture-in-picture mode

Another form of multi-task in iOS 9 is the video painting mode. Even if you quit, your video app can still play the video when you use another app, for example, you can write a diary or send an email while watching a TV drama. This is probably a feature that must be supported by all video apps and is easy to implement:

Use the iOS 9 SDK to build your app;

In app Capabilities, check "Audio, AirPlay, and Picture in Picture" of Background Modes ("Audio and AirPlay" in Xcode 7 beta ");

Set AudioSession Catogory as an appropriate option, suchAVAudioSessionCategoryPlayback

Use the AVKit, AVFoundation, or WebKit framework to play videos.

In iOS 9, the video playing part of our MediaPlayer framework has been officially announced. That is to say, if you are usingMPMoviePlayerViewControllerOrMPMoviePlayerControllerWhen you play a video, you will not be able to use the features of picture-in-picture. Therefore, transforming to a new video playing framework as soon as possible is an urgent adaptation task. Because the image-in-painting mode is based onAVPlayerLayer. When switching to an image in the picture, the layer of the video being played is taken out, zoomed out, and added to the layer of the new interface. This is also the main reason why the old MediaPlayer framework does not support image painting.

If you useAVPlayerViewControllerOnce these simple conditions are met, you should be able to see the picture-in-picture button in the lower right corner when playing a video in full screen using the corresponding frame. Whether you click this button to enter the picture-in-picture mode or directly use the Home key to switch to the background, the video that has been played will be reduced to the lower-right corner of the screen to become a picture-in-picture and kept playing. In the image-in-picture mode, the system adds a set of default controls on the AVPlayerLayer of the video to control the pause, resume, close, and return to the app. There is nothing to say about the first two controls. If we return an app, we need to handle the post-return operations by ourselves. In general, we want to restore to full screen mode and continue playing this video, becauseAVPlayerViewControllerDuring playback, we generally do not operate AVPlayerLayer, which must be implemented during restoration.AVPlayerViewControllerDelegate-PlayerViewController: restoreUserInterfaceForPictureInPictureStopWithCompletionHandler:To rebuild the UI based on the input ViewController, and pass true throughCompletionHandlerReturned to the system. The system has been notified that the recovery is successful (if the restoration fails, false must be passed ).

You can also use AVPlayerLayer to build a custom player. In this case, we need to pass in the AVPlayerLayer to create an AVPictureInPictureController. AVPictureInPictureController provides APIs to check whether the image-in-painting mode is supported, and other methods to control the image-in-painting behavior. Unlike using AVPlayerViewController directly, the system will return the reduced AVPlayerLayer to the previous view during restoration. We can use the corresponding methods in AVPictureInPictureControllerDelegate to learn the execution of the picture in the picture and restore the UI based on the situation of our app.

Summary

Based on the layout of AutoLayout and Size Class over the past few years, Apple released the killer of multitasking in iOS 9. It can be said that the demand for executing multiple apps on the same screen has been there since the early iPad, but now it is too late. In OS X 10.11, Apple also introduced similar features into the full screen mode of The OSX app, which can be said to be a further attempt to unify the OSX and iOS platforms.

However, there are still some shortcomings in Multitasking on the iPad. The biggest problem is that the app is still running in the sandbox, which means that we still cannot communicate between two apps on iOS: for example, opening a photo and a note app at the same time, you cannot drag an image to your note. Although XPC services are also available in iOS, third-party developers are not currently available, which limits the possibility of multi-tasking to some extent.

However, in general, the multitasking feature has greatly increased the usability of the iPad, which will certainly be one of the most commonly used and desired features in the future. It is very cost-effective to take a moment to learn how to make the Adaptive UI and enable the app to support multi-task operations.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.