![](/img/trans.png)
[英]Show UIViewController partially over a UIViewController with Swift
[英]Howto show an UIViewController over a UIViewcontroller as like a Popoverview
很难为我解释:-)
我已经有了:一个主要的UIViewController / UIView->有效第二个UIViewController / UIView,它在按下按钮后显示->有效,第二个UIViewController / UIView显示在屏幕顶部,并且具有完整的屏幕尺寸,所以我无法看到第一个UIViewController / UIView
因为我意识到我的secondView仅包含一些小组件,所以我想:将第一个UIViewController / UIView像弹出视图一样显示在第一个UIViewController / UIView上,因此第二个的尺寸很小,第一个仍显示在后面。
我以为我可以做到以下几点:
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)
}
}
我现在唯一的问题是,模态视图的大小太小,某些组件不完全可见。
尝试更改controller.preferredContentSize
以匹配您所需的大小
你有尝试过吗? iOS-如何控制模态视图控制器的大小?
要点:1.不要使用UIViewcontroller。 仅使用UIView。 2.如果加载模态视图控制器,则将卸载第一个UIViewController的视图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.