iOS 13 UIActivityViewController 在图像保存后自动呈现以前的 VC

标签 ios swift uiactivityviewcontroller ios13

我正在尝试实现“将图像保存到库”功能,然后返回到当前 View Controller ,但在新的 iOS 13 上,它会返回到呈现当前 View Controller 的 View Controller :

PHPhotoLibrary.requestAuthorization({(_ status: PHAuthorizationStatus) -> Void in })

let shareItems: Array = [newImg,"Hello"] as [Any]

let activityController = UIActivityViewController(activityItems: shareItems, applicationActivities: nil)

if UIDevice.current.userInterfaceIdiom == .pad {
    activityController.popoverPresentationController?.sourceView = saveButton
}

present(activityController, animated: true)

最佳答案

@KDP 解决方案的 Swift 版本:

let fakeViewController = TransparentViewController()
fakeViewController.modalPresentationStyle = .overFullScreen

activityViewController.completionWithItemsHandler = { [weak fakeViewController] _, _, _, _ in
    if let presentingViewController = fakeViewController?.presentingViewController {
        presentingViewController.dismiss(animated: false, completion: nil)
    } else {
        fakeViewController?.dismiss(animated: false, completion: nil)
    }
}
present(fakeViewController, animated: true) { [weak fakeViewController] in
    fakeViewController?.present(activityViewController, animated: true, completion: nil)
}

fakeViewController 要么在事件完成时关闭,要么我们需要在完成时关闭它。

关于iOS 13 UIActivityViewController 在图像保存后自动呈现以前的 VC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56903030/

相关文章:

ios - 编码协议(protocol)变量

ios,在其他所有内容之前显示警报,通知用户我们需要 "some"权限

iOS 8.1 Swift UIActivityViewController 不显示社交媒体共享(Facebook、twitter、WhatsApp 等)

ios - UIActivityViewController 的故障

ios - 错误 : Use of unresolved identifier 'indexPath'

iphone - 我如何为其他类的 TableView 和 UIView 设置背景图片

ios - 从主题标签正则表达式中删除点

swift - 在 iOS 13、Xcode 11 中呈现 View Controller 的问题

iOS,仅对应用程序功能的一部分使用生物识别身份验证

ios - 使用 Autolayout 根据宽度的比率设置 UIImage 高度