提高生产力的 iPad OS

目录

  • 概况

    • 文本编辑
    • 键盘(键盘浮动、拆分、速滑输入)
    • 多任务处理功能
    • 拖放
    • 整页截取标记
    • Safari 浏览器
  • 基于 iPadOS 进行开发

    • 将 iPad app 带入 Mac
    • Slide Over and Split View (水平滑动和拆分视图)
    • Drag and Drop (拖放)
    • Picture in Picture (画中画)
  • 拓展


一、概况
1.1、文本编辑
  • 三指捏和拷贝
  • 三指下放粘贴
  • 三指向左轻扫撤销操作
  • 光标导航、 优化文本选取、智能文本选择
1.2、键盘(键盘浮动、拆分、速滑输入)
1.3、多任务处理(“设置”>“主屏幕与程序坞”>“多任务处理”)
  • 侧拉打开App
  • 分屏浏览同时使用两个应用
  • 在应用之间拖放
1.4、整页截取标记
1.5、Safari 浏览器
  • 请求移动网站
  • 请求桌面站点

二、基于 iPad OS 进行开发
  • 2.1、将 iPad app 带入 Mac
- 需要重新生成证书
- 有太多iPad的痕迹,可能部分页面需要修改
- 布局方式
- 数据共享
- 代码共享
- 应用唤醒、通讯
- 系统开启:设置->主屏幕与程序坞->允许多个App

代码配置:
- 提供LaunchScreen.storyboard启动文件
- Info.plist做出如下相关配置

参考资料 - 史上第二走心的 iOS11 Drag & Drop 教程
参考资料 - WWDC 2017 iOS11 新特性 Drag and Drop 解析
参考资料 - Drag & Drop 改变了我对 iOS 的看法

  • Drag
- UIDragInteractionDelegate
- UITableViewDragDelegate
- UICollectionViewDragDelegate
- UITextDragDelegate
// 在添加 UIDragInteraction 对象之后,就具备了可被 Drag 的行为
UIDragInteraction *dragInter = [[UIDragInteraction alloc] initWithDelegate:self];
[self.firstImageView addInteraction:dragInter];
self.firstImageView.userInteractionEnabled = YES;

#pragma mark - UIDragInteractionDelegate
// 单指长按某个 View 时,如果添加了 UIDragInteraction,Drag 即刻启动,进入 itemsForBeginningSession 的回调
- (NSArray<UIDragItem *> *)dragInteraction:(UIDragInteraction *)interaction itemsForBeginningSession:(id<UIDragSession>)session {
    /**
     1、UIDragInteraction 可以包含多个 UIDragSession
     2、每个 UIDragSession 又可以包含多个 UIDragItem
     3、UIDragItem 则是 Drop 时接收方所受到的对象
     */
    return [self itemsForSession:session];
}

// 如何生成 UIDragItem 呢
- (NSArray*)itemsForSession:(id<UIDragSession>)session {
    NSItemProvider *provider = [[NSItemProvider alloc] initWithObject:self.firstImageView.image];
    UIDragItem *dragItem = [[UIDragItem alloc] initWithItemProvider:provider];
    dragItem.localObject = self.firstImageView.image;
    return @[dragItem];
}
  • Drop
- UIDropInteractionDelegate
- UITableViewDropDelegate
- UICollectionViewDropDelegate
- UITextDropDelegate
UIDropInteraction *dropInteraction = [[UIDropInteraction alloc] initWithDelegate:self];
[self.secondImageView addInteraction:dropInteraction];
self.secondImageView.userInteractionEnabled = YES;

#pragma mark - UIDropInteractionDelegate
- (BOOL)dropInteraction:(UIDropInteraction *)interaction canHandleSession:(id<UIDropSession>)session{
    if(session.localDragSession == nil){
        // 如果是来自于外部 App 的 Drag,localDragSession 为 nil
        return YES;
    }
    return [session canLoadObjectsOfClass:[UIImage class]];
}

- (UIDropProposal *)dropInteraction:(UIDropInteraction *)interaction sessionDidUpdate:(id<UIDropSession>)session{
    /**
     如果禁止外部app拖动到这里的话直接 UIDropOperationCancel 就行了
    
     UIDropOperation opera = session.localDragSession ? UIDropOperationCopy : UIDropOperationCancel;
     return [[UIDropProposal alloc] initWithDropOperation:opera];
     */
    return [[UIDropProposal alloc] initWithDropOperation:UIDropOperationCopy];
}

- (void)dropInteraction:(UIDropInteraction *)interaction performDrop:(id<UIDropSession>)session{
    // performDrop 中的操作最好是采用异步的方式,任何费时的操作都会导致主线程的卡
    [session loadObjectsOfClass:[UIImage class]
                     completion:^(NSArray<__kindof id<NSItemProviderReading>> * _Nonnull objects) {
        for (id object in objects) {
            UIImage *image = (UIImage*)object;
            if (image) {
                // handle image
                self.secondImageView.image = image;
            }
        }
    }];
}
- 系统开启“画中画”:设置->主屏幕与程序坞->多任务->画中画
- SDK支持:AVKit,AV Foundation、WebKit类进行播放
- AVKit->AVPlayerViewController默认开启PiP,如果想要关闭添加如下代码
if (@available(iOS 9.0, *)) {
    _avPlayerController.allowsPictureInPicturePlayback = NO;
}

- WebKit->WKWebView 默认开启画中画,如果想关闭直接添加如下代码
if (@available(iOS 9.0, *)) {
    _appConfiguration.allowsPictureInPictureMediaPlayback = NO;
}

三、拓展

  • 3.1、遇到的问题:实用WKWebView播放优酷视频链接失败
    原因:iPad OS 在设置-> Safari浏览器 -> 请求桌面网站开启了,只要把它关掉就正常了,但是你又不能要求审核人员或者用户自己去把它关了,所以,在项目中手动关掉。
原因:使用移动设备获取网站的视频地址
if (@available(iOS 13.0, *)) {
    _appConfiguration.defaultWebpagePreferences.preferredContentMode = WKContentModeMobile;
}

参考文章:WKWebView 在 iOS13 iPadOS 获取到的UserAgent中的设备变成Macintosh的问题

未完待续

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章