簡體   English   中英

顯示的彈出窗口沒有覆蓋整個屏幕 swift

[英]Pop up displayed is not covering the entire screen swift

在此處輸入圖片說明

我是 iOS 開發的新手,我在屏幕上點擊按鈕時顯示了彈出窗口,但它沒有覆蓋整個屏幕,顯示彈出窗口的代碼

let popOverVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "sbPopUpID") as! PopUpViewController
self.addChild(popOverVC)
popOverVC.view.frame = self.view.frame
self.view.addSubview(popOverVC.view)
popOverVC.didMove(toParent: self)

您需要添加 AutoLayout 約束。 這個片段應該可以幫助你。

addChild(childViewController)
view.addSubview(childView)
childView.translatesAutoresizingMaskIntoConstraints = false
view.topAnchor.constraint(equalTo: childView.topAnchor).isActive = true
view.bottomAnchor.constraint(equalTo: childView.bottomAnchor).isActive = true
view.leftAnchor.constraint(equalTo: childView.leftAnchor).isActive = true
view.rightAnchor.constraint(equalTo: childView.rightAnchor).isActive = true
childViewController.didMove(toParent: self)

你可以簡單地展示一個:

let popOverVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "sbPopUpID") as! PopUpViewController
// This one makes popOverVC fullscreen. In some cases you would like to use `.overFullScreen` just test what fits your scenario better
popOverVC = .fullScreen
// if you need it without animation, just call with animated: false
self.present(popOverVC, animated: true, completion: nil)

我也推薦閱讀這篇文章

https://developer.apple.com/documentation/uikit/uiviewcontroller/1621380-presentviewcontroller?language=objc

和這個

https://developer.apple.com/documentation/uikit/uiviewcontroller/1621355-modalpresentationstyle?language=objc

更好地了解正在發生的事情:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM