我在iPad和Mac的应用程序中有一个弹出控制器(使用mac催化剂),当它已经出现时,我正试图找出如何增加弹出器的高度。我一直在寻找如何做到这一点,但我发现的一切都是在展示之前设置大小,而不是在之后。
当弹出显示时,中有一个按钮,它的高度应该增加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)
}
发布于 2022-02-11 13:47:33
若要在popover视图中更改已呈现控制器的大小,应修改其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)
}
}
https://stackoverflow.com/questions/70981202
复制相似问题