【发布时间】:2017-08-30 09:11:42
【问题描述】:
以下 Swift 3 代码(归功于 Hacking With Swift)创建了一个 UIAlertController,并通过 UIPopoverPresentationController API 在 iPad 上以 CGRect 坐标的弹出窗口成功呈现它:
func popUpToSelectTheLanguage(){
let ac = UIAlertController(title: "Set expected language...", message: nil, preferredStyle: .actionSheet)
ac.addAction(UIAlertAction(title: "English", style: .default, handler: { (action) in /* Action to take */ }))
ac.addAction(UIAlertAction(title: "French", style: .default, handler: { (action) in /* Action to take */ }))
ac.addAction(UIAlertAction(title: "Cancel", style: .cancel))
let popover = ac.popoverPresentationController
popover?.sourceView = view
popover?.sourceRect = CGRect(x: 32, y: 32, width: 64, height: 64)
present(ac, animated: true)
}
但是,当尝试将不同的UIViewController 显示为弹出窗口时,UIReferenceLibraryViewController(系统的单语/双语词典)会覆盖整个屏幕,而不是作为弹出窗口出现。
func popUpTheDictionary(){
let dic = UIReferenceLibraryViewController(term: "hi" as String)
let popover = dic.popoverPresentationController
popover?.sourceView = view
popover?.sourceRect = CGRect(x: 32, y: 32, width: 64, height: 64)
present(dic, animated: true)
}
这里有什么问题?是否需要进一步设置 UIReferenceLibraryViewController,或者它只是被锁定以防止显示为弹出窗口?
我的目标是 iOS 10.2,通用;为 iPad Pro(12.9 英寸)构建。
如果没有办法解决这个问题,我同样会接受任何提供通过另一个库将UIReferenceLibraryViewController 呈现为弹出窗口所需的代码的答案(如果它在 iPhone 和 iPad 上作为弹出窗口工作,则加分)。
【问题讨论】:
标签: ios swift ipad uiviewcontroller popup