我有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)
答案 0 :(得分:-2)
选择要编辑的字段。进行类似图片的设置。我希望它有所帮助。