【问题标题】:Howto show an UIViewController over a UIViewcontroller as like a Popoverview如何在 UIViewcontroller 上显示 UIViewController 就像 Popoverview
【发布时间】:2015-07-23 09:32:28
【问题描述】:

对我来说很难解释 :-)

我已经有: 一个主 UIViewController/UIView -> 工作 我在按下按钮后显示的第二个 UIViewController/UIView -> 工作,第二个 UIViewController/UIView 显示在屏幕顶部并具有全屏尺寸,所以我看不到第一个 UIViewController/UIView

因为我意识到我的 secondView 只包含一些小组件,所以我想: 在第一个 UIViewController/UIView 上显示第二个 UIViewController/UIView 就像 popoverview 一样,所以第二个的尺寸最小,第一个仍然显示在后面。

我认为我可以简单地执行以下操作:

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let vc = storyboard.instantiateViewControllerWithIdentifier("Options") as! UIViewController

    vc.modalPresentationStyle = .Popover <<-- Make simply Modal ?

    self.presentViewController(vc, animated: true, completion: nil)

但第二个仍然全屏显示。 有什么帮助吗?

更新我只是通过结合在互联网上找到的东西而不知道我到底在做什么:-)

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.sourceView.sizeToFit();

    // present (id iPhone it is a modal automatic full screen)
    self.presentViewController(controller, animated: true, completion: nil)
}

}

我现在唯一的问题是,模态视图的尺寸太小,一些组件不完全可见。

【问题讨论】:

标签: swift uiview uiviewcontroller modal-dialog


【解决方案1】:

尝试更改controller.preferredContentSize 以匹配您想要的大小

【讨论】:

  • 谢谢。那真是太好了。你知道如何摆脱箭头吗?
  • 我想我确实在你的另一个question中回答了这个问题
【解决方案2】:

你试过吗? iOS -- how do you control the size of a modal view controller?

要点: 1.不要使用UIViewcontroller。只使用 UIView。 2. 如果你加载一个模态视图控制器,第一个 UIViewController 的视图将被卸载。

【讨论】:

  • 我不认为我可以使用 UIView 本身,因为我的第二个 UIViewController 中有按钮和与标准控件的交互。我不知道。我会检查的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多