gpt4 book ai didi

swift - 如何成长一个弹出 Controller

转载 作者:行者123 更新时间:2023-12-05 04:35:42 27 4
gpt4 key购买 nike

我的 iPad 和 Mac 应用程序中有一个 popover Controller (使用 mac catalyst),我正在尝试弄清楚如何在 popover 已经呈现时增加它的高度。我一直在到处搜索如何执行此操作,但我发现的所有内容都是关于在呈现之前而不是之后设置大小。

弹出窗口显示时,其中有一个按钮应该将高度增加 100-150 像素,但我不知道该怎么做

谁能帮我解决这个问题?提前致谢!

这是我的弹出窗口呈现代码:

func openView(sourceView: UIView?, sourceRect: CGRect?) {
let vc = ViewControllerA()

//Try popover
if let sourceView = sourceView,
let sourceRect = sourceRect {
vc.modalPresentationStyle = .popover

if let popover = vc.popoverPresentationController {
vc.preferredContentSize = return CGSize(width: 390, height: 390)
vc.presentationController?.delegate = self

popover.sourceView = sourceView
popover.sourceRect = sourceRect
popover.permittedArrowDirections = [.up, .left]

self.present(vc, animated: true, completion: nil)
return
}
}


//present it normally if there's no source view
vc.modalPresentationStyle = .overCurrentContext
vc.modalTransitionStyle = .crossDissolve

self.present(vc, animated: true, completion: nil)
}

最佳答案

要更改弹出 View 中显示的 Controller 的大小,您应该修改其 preferredContentSize 属性:

@IBAction func showPopover(_ sender: UIButton) {
// Create controller
guard let controller = storyboard?.instantiateViewController(withIdentifier: "Popover") else {
return
}
controller.modalPresentationStyle = .popover
controller.preferredContentSize = CGSize(width: 200, height: 200)

// Configure popover
guard let popover = controller.popoverPresentationController else {
return
}
popover.permittedArrowDirections = .up
popover.sourceView = self.view
popover.sourceRect = sender.frame
popover.delegate = self
present(controller, animated: true, completion: nil)

// Change height after 3 secs
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
controller.preferredContentSize = CGSize(width: 200, height: 400)
}
}

关于swift - 如何成长一个弹出 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70981202/

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