[英]How to change size of Popover view
I am trying to lay out a popover view when a button on current view is pressed.当按下当前视图上的按钮时,我试图布置一个弹出视图。 This works fine with following code but problem is that the popover view does not take the size from .preferredContentSize.
这适用于以下代码,但问题是弹出视图不采用 .preferredContentSize 的大小。
IngredientVC.preferredContentSize = CGSize(width: 200, height: 300) IngredientVC.preferredContentSize = CGSize(宽:200,高:300)
Popover view has height and width of current view.弹出视图具有当前视图的高度和宽度。 How do I make Popover view smaller size please?
请问如何让 Popover 视图变小?
@IBAction func actionIngredients(_ sender: Any)
{
// Load and configure your view controller.
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let IngredientVC = storyboard.instantiateViewController(
withIdentifier: "testViewIdentifier")
//let IngredientVC:testViewController = testViewController()
// Use the popover presentation style for your view controller.
IngredientVC.modalPresentationStyle = .popover
IngredientVC.preferredContentSize = CGSize(width: 200, height: 300)
// Specify the anchor point for the popover.
//IngredientVC.popoverPresentationController?.barButtonItem =
//optionsControl
//let popovercontroller = optionsVC.popoverPresentationController
IngredientVC.popoverPresentationController?.delegate = self
IngredientVC.popoverPresentationController?.sourceView = self.view
IngredientVC.popoverPresentationController?.sourceRect = CGRect(x:self.view.frame.width/2, y: self.view.frame.height/2,width: 200,height: 300)
IngredientVC.popoverPresentationController?.permittedArrowDirections = [.down, .up]
// Present the view controller (in a popover).
self.present(IngredientVC, animated: true)
}
Note: I have popover view controller in Storyboard with Simulated Metrics size as "Freeform".注意:我在 Storyboard 中有弹出视图控制器,模拟指标大小为“自由格式”。
I figured out that all I needed was following function -我发现我所需要的只是遵循功能 -
func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle
{
return UIModalPresentationStyle.none
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.