如何解决如何为 iPad 动态更改弹出框的高度
我有一个包含文本和开关的弹出窗口/弹出窗口。标签和开关位于 UIView 内的 stackView 中。 stackView 受到约束,因此当 stackView 根据其内容更改大小时,UIView 也会更改。当我更改为另一种语言(例如法语)时,文本字符串会变长,这会导致弹出窗口中的标签添加第二行文本。这反过来又使弹出框的高度变高。
问题来了: 据我所知,弹出框的高度是在打开弹出框的视图(TallY_VC)上的准备转场中设置的。直到 viewDidAppear 在 popover VC (Tallly_Popover_VC) 的代码中运行时,popover 的新高度才会确定。所以这意味着在准备转场运行时,popover 所需的高度是不确定的。
对于 iPhone,高度是自动设置的。有没有办法让 iPad 的弹出框高度像 iPhone 一样自动更改,或者是唯一的方法 preferredContentSize?
下面是在 TallY_VC 视图控制器中准备转场代码。这是我想出的为每种语言设置弹出框高度的唯一方法。我使用 Bundle.main.preferredLocalizations.first 来获取当前语言,然后手动设置 preferredContentSize 高度。这行得通,但当我有 15 或 20 种语言时,它会很费力。提前致谢。
override func prepare(for segue: UIStoryboardSegue,sender: Any?)
{
let storyboard : UIStoryboard = UIStoryboard(name: "Tally_Popover",bundle: nil)
var popupVC: Tallly_Popover_VC = storyboard.instantiateViewController(withIdentifier: "Tallly_Popover") as! Tallly_Popover_VC
let navigationController = UINavigationController(rootViewController: popupVC)
var preferredLang: String = "en"
var theHeight: Int = 471
let deviceName = UIDevice().type
let deviceString: String = ("\(deviceName)")
if segue.identifier == "tally_pop"
{
if deviceString.contains("iPad")
{
popupVC = segue.destination as! Tallly_Popover_VC
preferredLang = Bundle.main.preferredLocalizations.first ?? "en"
if preferredLang == "fr"
{
theHeight = 551
} else if preferredLang == "en" {
theHeight = 471
}
popupVC.preferredContentSize = CGSize(width: 310,height: theHeight)
navigationController.isNavigationBarHidden = true
} else if deviceString.contains("iPhone") {
present(navigationController,animated: true)
navigationController.isNavigationBarHidden = false
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。