![](/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.