如何以编程方式调整模态视图的大小 (SWIFT)
Howto Size the Modal View programmatically (SWIFT)
我只是想在现有主 UIViewController/UIView 上显示一个小选项对话框,这样在 IPad 上我会看到一个小对话框,在后台我会看到主视图。
我设法在模态视图样式中显示 UIViewController/UIView,如下所示:
func showoptions(){
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewControllerWithIdentifier("Options") as! UIViewController
controller.modalPresentationStyle = UIModalPresentationStyle.Popover
let popoverPresentationController = controller.popoverPresentationController
// result is an optional (but should not be nil if modalPresentationStyle is popover)
if let _popoverPresentationController = popoverPresentationController {
// set the view from which to pop up
_popoverPresentationController.sourceView = self.view;
//_popoverPresentationController.sourceRect = CGRectMake(60, 100, 500, 500)
//_popoverPresentationController. .setPopoverContentSize(CGSizeMake(550, 600), animated: true)
//_popoverPresentationController.sourceView.sizeToFit();
// present (id iPhone it is a modal automatic full screen)
self.presentViewController(controller, animated: true, completion: nil)
}
}
但我还有一些问题:
1. 如何去掉边框显示的箭头。
2. 如何调整此模态视图的大小。它显示为小,我想将它安装到 UIControllerView/UIView.
中最大的控件
有什么帮助吗?
我需要类似的东西,最终将视图控制器呈现为在当前上下文中具有透明背景的模态。在那里我用我想要的东西制作了一个更小的不透明 UIView 。
- 尝试将
_popoverPresentationController.permittedArrowDirections
更改为空选项集
- 更改
controller.preferredContentSize
以匹配您想要的尺寸
我只是想在现有主 UIViewController/UIView 上显示一个小选项对话框,这样在 IPad 上我会看到一个小对话框,在后台我会看到主视图。
我设法在模态视图样式中显示 UIViewController/UIView,如下所示:
func showoptions(){
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewControllerWithIdentifier("Options") as! UIViewController
controller.modalPresentationStyle = UIModalPresentationStyle.Popover
let popoverPresentationController = controller.popoverPresentationController
// result is an optional (but should not be nil if modalPresentationStyle is popover)
if let _popoverPresentationController = popoverPresentationController {
// set the view from which to pop up
_popoverPresentationController.sourceView = self.view;
//_popoverPresentationController.sourceRect = CGRectMake(60, 100, 500, 500)
//_popoverPresentationController. .setPopoverContentSize(CGSizeMake(550, 600), animated: true)
//_popoverPresentationController.sourceView.sizeToFit();
// present (id iPhone it is a modal automatic full screen)
self.presentViewController(controller, animated: true, completion: nil)
}
}
但我还有一些问题: 1. 如何去掉边框显示的箭头。 2. 如何调整此模态视图的大小。它显示为小,我想将它安装到 UIControllerView/UIView.
中最大的控件有什么帮助吗?
我需要类似的东西,最终将视图控制器呈现为在当前上下文中具有透明背景的模态。在那里我用我想要的东西制作了一个更小的不透明 UIView 。
- 尝试将
_popoverPresentationController.permittedArrowDirections
更改为空选项集 - 更改
controller.preferredContentSize
以匹配您想要的尺寸