我有一个iPhone应用程序,我试图普及 . 我有这个代码:
let documentMenu = UIDocumentMenuViewController(documentTypes: [kUTTypeContent as String], inMode: .Import)
documentMenu.modalPresentationStyle = .FormSheet
documentMenu.delegate = self
self.presentationContext.presentViewController(documentMenu, animated: true, completion: nil)
self.presentationContext
只是传递给类的视图控制器 .
每次执行此代码时,都会发生此错误:
您的应用程序提供了一个UIDocumentMenuViewController() . 在其当前的特征环境中,具有此样式的UIDocumentMenuViewController的modalPresentationStyle是UIModalPresentationPopover . 您必须通过视图控制器的popoverPresentationController为此弹出窗口提供位置信息 . 您必须提供sourceView和sourceRect或barButtonItem . 如果在呈现视图控制器时不知道此信息,则可以在UIPopoverPresentationControllerDelegate方法-prepareForPopoverPresentation中提供该信息 .
我不确定发生了什么 . 我甚至试图设置 sourceView
和 sourceRect
,它确实停止了错误,然而,它将 DocumentMenuViewController
固定在一个弹出框中,我不是那样的 . 我需要在屏幕中央以模态方式呈现 . 任何帮助表示赞赏 .
2 回答
问题是
UIDocumentMenuViewController
不希望显示为较小的"popover"演示样式以外的任何内容 . 它自己的实现覆盖了modalPresentationStyle
到.Popover
的任何设置 . 因此,您最终会忽略将样式设置为.FormSheet
的尝试 .这是导致错误的原因 . 一旦样式为
.Popover
,您必须执行错误状态并设置sourceView
和sourceRect
或barButtonItem
的适当组合 .向Apple提交增强请求,以支持其他模式演示样式 . 在此期间,您需要调整UI .