【问题标题】:Howto Size the Modal View programmatically (SWIFT)如何以编程方式调整模态视图的大小 (SWIFT)
【发布时间】:2015-07-23 11:27:57
【问题描述】:

我只是想在现有的主 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 中最大的控件中。

有什么帮助吗?

【问题讨论】:

    标签: swift uiview uiviewcontroller modal-dialog


    【解决方案1】:
    1. 尝试将_popoverPresentationController.permittedArrowDirections 更改为空选项集
    2. 更改 controller.preferredContentSize 以匹配您想要的大小

    【讨论】:

    • 完美。非常感谢。
    • 究竟有什么不适合您?箭头可见吗?尺寸不正确吗?
    【解决方案2】:

    我需要类似的东西,最终将视图控制器呈现为在当前上下文中具有透明背景的模态。在那里,我用我想要的东西做了一个更小的不透明 UIView。

    【讨论】:

    • 谢谢。我知道我可以做自己的视图,也可以做自己的控件,但为什么不使用 UIViewController 的现有概念。我与按钮和段控件交互。有没有办法用我的 UIViewController 做到这一点?
    猜你喜欢
    • 1970-01-01
    • 2011-02-27
    • 1970-01-01
    • 1970-01-01
    • 2018-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-09
    相关资源
    最近更新 更多