[英]Howto show an UIViewController over a UIViewcontroller as like a Popoverview
Difficult to explain for me :-) 很难为我解释:-)
I already have: A main UIViewController/UIView -> works A second UIViewController/UIView which I show after a button is pressed -> works, second UIViewController/UIView is shown on top of screen and has the full screensize, so I can't see the first UIViewController/UIView 我已经有了:一个主要的UIViewController / UIView->有效第二个UIViewController / UIView,它在按下按钮后显示->有效,第二个UIViewController / UIView显示在屏幕顶部,并且具有完整的屏幕尺寸,所以我无法看到第一个UIViewController / UIView
Because I realized my secondView holds only some small components, I would like: to show the second UIViewController/UIView over the first as like a popoverview, So the second is sized minimal and the first is still shown in the back. 因为我意识到我的secondView仅包含一些小组件,所以我想:将第一个UIViewController / UIView像弹出视图一样显示在第一个UIViewController / UIView上,因此第二个的尺寸很小,第一个仍显示在后面。
I thought I could do simply the following: 我以为我可以做到以下几点:
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)
But still the second is shown on full screen. 但是第二个还是全屏显示。 Any help ?
有什么帮助吗?
Update I just managed to do by combining stuff found in the internet without knowing what I exactly I am doing :-) 更新我只是设法结合了互联网上发现的东西而做到了,却不知道我到底在做什么:-)
func showoptions(){ 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)
}
} }
The only prolem I have now is, that the size of the modal view is too small, some compontents are not fully visible. 我现在唯一的问题是,模态视图的大小太小,某些组件不完全可见。
尝试更改controller.preferredContentSize
以匹配您所需的大小
Have you tried this? 你有尝试过吗? iOS -- how do you control the size of a modal view controller?
iOS-如何控制模态视图控制器的大小?
Bullet points: 1. do not use UIViewcontroller. 要点:1.不要使用UIViewcontroller。 use just UIView.
仅使用UIView。 2. the first UIViewController's view will be unloaded if u loading a modal view controller.
2.如果加载模态视图控制器,则将卸载第一个UIViewController的视图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.