ios - Wrong frame adding ViewController View as subview -


i'm working on custom scrollview display different views of different types pagination.

for view in views {             view.frame = frame             frame.origin.x += width         } contentviewwidth.constant = width * cgfloat(pages.count) self.setneedsupdateconstraints() 

works kind of custom view subclass.

now have add viewcontroller "page", doing:

parentviewcontroller?.addchildviewcontroller(containedviewcontroller)         let width = scrollview.frame.size.width         let height = scrollview.frame.size.height         var frame = cgrect(x: 0, y: 0, width: width, height: height)         containedviewcontroller.view.frame = frame         pages.append(containedviewcontroller.view)         contentview.addsubview(containedviewcontroller.view)         containedviewcontroller.didmove(toparentviewcontroller: parentviewcontroller) 

i right frame when setting it, bug inspecting complete scrollview totally random frame size. i'm using scrollview full screen on 7plus, su 414 width, result view width > 500 px.

what i'm missing?

always better add uiview container view , set frame of viewcontroller.view that. viewcontroller.view.frame tends messy reason, on rotation / dynamic layout... try

parentviewcontroller?.addchildviewcontroller(containedviewcontroller)  let width = scrollview.frame.size.width let height = scrollview.frame.size.height let frame = cgrect(x: 0, y: 0, width: width, height: height)  let containerview = uiview(frame:frame)  //potentially add flexible width , height    containedviewcontroller.view.autoresizingmask = [.flexiblewidth,.flexibleheight]  containedviewcontroller.view.frame = containerview.frame  pages.append(containerview) // assuming array of views inside scrollview i'd change containerview well.. bit of guess though.  containerview.addsubview(containedviewcontroller.view) contentview.addsubview(containerview) containedviewcontroller.didmove(toparentviewcontroller: parentviewcontroller) 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -