iPad分屏适配的一些小坑

1,153 阅读2分钟

OS9开始,iPad开始支持split view分屏功能。

If you transition an older project to iOS 9, make your app eligible for Slide Over and Split View by ensuring your Xcode project is configured as follows:

  • Set the Base SDK to “Latest iOS,” as described in Setting the Base SDK in App Distribution Guide.
  • Provide a LaunchScreen.storyboard file (instead of a .png image file as you did in iOS 7 and earlier), as described in Creating a Launch Screen File in App Distribution Guide.
  • In your project’s Info.plist file, in the “Supported interface orientations (iPad)” array, declare support for all four device orientations, as shown here:

image.png NOTE

If you must opt out of Slide Over and Split View, do so explicitly by adding the UIRequiresFullScreen key to your Xcode project’s Info.plist file and apply the Boolean value YES. You can do this in the property list editor or in the General > Deployment Info area in the target editor.

TIP

A user can disable Slide Over and Split View in Settings > General > Multitasking. If you think you’ve set up everything correctly and find that these features still don’t work, check this setting.

根据官方说明可以看出如果支持分屏,需要info.plist中的“Supported interface orientations (iPad)”属性对应的值包含了四个方向,同时**UIRequiresFullScreen对应的值为NO**,且需要使用LaunchScreen作为启动页。

项目开启分屏可能会引发打包错误

可能会出现如下的报错:

Invalid Bundle. Your app supports Multitasking on iPad, so you must include the UILaunchStoryboardName key in your bundle, 'com.XXXXX.xxxx. Learn more 网上大部分给的解决方案是 Targets - General - Deployment info - 勾选 Requires full screen

然而如果需要你的项目需要开启分屏,那么这个解决方案和项目要求背道而驰,此时的解决方案应如下图所示,调整为UILaunch作为启动页,当然这时候要麻烦设计了。

image.png

开启分屏后无法限制屏幕方向

开启分屏后无法限制屏幕旋转方向,也就是分屏时

系统将忽略下面两处代码:

  • UIApplicationDelegate中的supportedInterfaceOrientationsForWindow:方法
  • UIViewController通过supportedInterfaceOrientations方法设置的自己支持的屏幕方向 以及UIViewControllershouldAutorotate的值。 这可能会导致在旋转时布局出现错乱,开发过程中需要多验证旋转屏幕的情况,及时发现问题处理解决。

分屏时无法获取到相机权限

如果项目中有使用AVCaptureDeviceInput调用相机,而当分屏调用相机时系统要求应用具有com.apple.developer.avfoundation.multitasking-camera-access 才可以访问相机权限。

此时可以考虑使用UIImagePickerController,使用系统相机可在分屏时使用相机功能拍摄。 另外一般视频采集都使用 AVCaptureDeviceInput,例如微信视频通话,这都需要增加在分屏时对视频采集相关功能的禁用提醒。

更多可以访问苹果官方说明了解:developer.apple.com/documentati…