【发布时间】: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)
}
}
我现在唯一的问题是,模态视图的尺寸太小,一些组件不完全可见。
【问题讨论】:
-
不确定,是否有帮助。可能我不明白,但我不想要一个带有箭头的弹出框。我只想将 UIView 显示在另一个之上。
-
看看这个答案,我很久以前就发过了。 stackoverflow.com/questions/24635744/…
标签: swift uiview uiviewcontroller modal-dialog