Swift 以编程方式创建的UIPopoverPresentationController填充屏幕
我正在以编程方式创建的弹出窗口将填充屏幕。正如您从示例代码中看到的,我尝试了许多方法来限制它的大小,但没有一种有效。此外,不会调用委托方法。有什么想法吗?在过去,我曾成功地使用CALayer来处理这类事情,但我认为这会更简单——也许不会Swift 以编程方式创建的UIPopoverPresentationController填充屏幕,swift,uikit,uipopoverpresentationcontroller,Swift,Uikit,Uipopoverpresentationcontroller,我正在以编程方式创建的弹出窗口将填充屏幕。正如您从示例代码中看到的,我尝试了许多方法来限制它的大小,但没有一种有效。此外,不会调用委托方法。有什么想法吗?在过去,我曾成功地使用CALayer来处理这类事情,但我认为这会更简单——也许不会 @objc func touchDownHandler(sender: UISlider) { let popoverController = UIViewController() popoverController.view.backgroun
@objc func touchDownHandler(sender: UISlider) {
let popoverController = UIViewController()
popoverController.view.backgroundColor = .red
popoverController.view.frame = CGRect(x: 0, y: 0, width: 200, height: 200)
let textLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
textLabel.text = "Hello World"
textLabel.backgroundColor = .green
popoverController.view.addSubview(textLabel)
popoverController.modalPresentationStyle = UIModalPresentationStyle.popover
popoverController.preferredContentSize = CGSize(width: 200, height: 200)
if let popoverPresentation = popoverController.popoverPresentationController {
popoverPresentation.delegate = self
popoverPresentation.sourceRect = sender.frame
popoverPresentation.popoverLayoutMargins = UIEdgeInsets(top: 10, left: 10, bottom: 210, right: 210)
popoverPresentation.backgroundColor = .blue
self.controller.present(popoverController, animated: true, completion: {
print("pop over is visible")
})
}
}
请记住,根据Apple文档,“在水平紧凑的环境中,.popover选项的行为与UIModalPresentationStyle.fullScreen相同。”
请记住,根据Apple文档,“在水平紧凑的环境中,.popover选项的行为与UIModalPresentationStyle.fullScreen相同。”谢谢。看起来我为任务选择了错误的组件。如果你作出评论和回答,我可以接受。