gpt4 book ai didi

ios - UIReferenceLibraryViewController 无法显示为弹出窗口(始终覆盖全屏)

转载 作者:行者123 更新时间:2023-11-28 12:26:39 25 4
gpt4 key购买 nike

以下 Swift 3 代码(归功于 Hacking With Swift)创建了一个 UIAlertController 并通过UIPopoverPresentationController应用程序接口(interface):

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)。

最佳答案

您需要将 View Controller 的 modalPresentationStyle 设置为 .popover

func popUpTheDictionary(){
let dic = UIReferenceLibraryViewController(term: "hi" as String)
dic.modalPresentationStyle = .popover // add this

let popover = dic.popoverPresentationController
popover?.sourceView = view
popover?.sourceRect = CGRect(x: 32, y: 32, width: 64, height: 64)
present(dic, animated: true)
}

UIAlertController 为您做这件事,因为它始终是一个弹出窗口。

关于ios - UIReferenceLibraryViewController 无法显示为弹出窗口(始终覆盖全屏),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43219587/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com