[英]Child view controller resizes when I reopen the height
我有3個視圖控制器,我想將它們嵌入到ScrollView,Snapchat樣式中(以便您可以在它們之間滑動)。 但是我面臨一個非常奇怪的問題,導航欄似乎緊貼着狀態欄,
但是當我離開應用程序(例如回到主屏幕)並返回時,它向下移動。
這是我的代碼:
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
self.mainScrollView.delaysContentTouches = false
let v1 = storyboard.instantiateViewController(withIdentifier: "profileViewController") as! profileViewController
self.addChildViewController(v1)
self.mainScrollView.addSubview(v1.view)
v1.didMove(toParentViewController: self)
//--------
let v2 : recordViewController = recordViewController(nibName: "recordViewController", bundle: nil)
self.addChildViewController(v2)
self.mainScrollView.addSubview(v2.view)
v2.didMove(toParentViewController: self)
//--------
let v3 = storyboard.instantiateViewController(withIdentifier: "discoverViewController") as! discoverViewController
self.addChildViewController(v3)
self.mainScrollView.addSubview(v3.view)
v3.didMove(toParentViewController: self)
//--------
var v1frame : CGRect = self.mainScrollView.bounds
v1frame.origin.x = 0
v1.view.frame = v1frame
//v1.view.bindFrameToSuperviewBounds()
var v2frame : CGRect = self.mainScrollView.bounds
v2frame.origin.x = self.view.frame.width
v2.view.frame = v2frame
var v3frame : CGRect = self.mainScrollView.bounds
v3frame.origin.x = self.view.frame.width*2
v3.view.frame = v3frame
到目前為止,我的解決方案都是以編程方式添加約束,但是我無法弄清楚應該添加哪些約束。 這是我嘗試過的
let csH = NSLayoutConstraint.constraints(withVisualFormat: "H:|-0-[v]-0-|", options: [], metrics: [:], views: ["v": recordView])
let csV = NSLayoutConstraint.constraints(withVisualFormat: "V:|-0-[v]-0-|", options: [], metrics: [:], views: ["v": recordView])
view.addConstraints(csH)
view.addConstraints(csV)
選擇您要編輯的字段。 進行圖片設置。 希望對您有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.