ios - swift subview does not full-fill parent view -
when app starts, use method set root view controller.
func showrootviewcontroller() { let sb = uistoryboard.init(name: "main", bundle: nil) let mainviewcontroller = sb.instantiateinitialviewcontroller()! self.window?.rootviewcontroller = mainviewcontroller self.window?.makekeyandvisible() }
in main view controller, i've code set view container view
class mainviewcontroller: uiviewcontroller { @iboutlet weak var headerview: uiview! @iboutlet weak var containerview: uiview! override func viewdidload() { super.viewdidload() } override func viewdidappear(_ animated: bool) { super.viewdidappear(animated) if(usermanager.hasregistered()) { let sb = uistoryboard.init(name: "login", bundle: nil) self.setcontentviewcontroller(sb.instantiateinitialviewcontroller()!) } else { let sb = uistoryboard.init(name: "registration", bundle: nil) self.setcontentviewcontroller(sb.instantiateinitialviewcontroller()!) } } func setcontentviewcontroller(_ contentviewcontroller: uiviewcontroller) { print(self.containerview.frame) let contentview = contentviewcontroller.view! contentview.frame = self.containerview.bounds self.containerview.addsubview(contentview) } }
let @ view, have container view used add subviews. set background address frame of container view
the subview designed below:
the result not expected. containerview has gone somewhere (i don't know), subview move on top.
please me.
contentview frame setted in wrong position. should move line of code:
contentview.frame = self.containerview.bounds
in
override func func viewdidlayoutsubviews() { super.viewdidlayoutsubviews() contentview.frame = self.containerview.bounds }
Comments
Post a Comment