objective c - How to resize Subview with Autolayout -


i have tableview view, resson, have add tableview in scrollview. used autolayout tableview not auto resize when rotate screen landscape.

how make tableview including same size scrollview when rotate sreen landscape?

here code:

scrollviewmain = uiscrollview() scrollviewmain.contentinset = uiedgeinsets(top: 34, left: 0, bottom: 52, right: 0) scrollviewmain.scrollindicatorinsets = uiedgeinsets(top: 34, left: 0, bottom: 52, right: 0) scrollviewmain.delegate = self scrollviewmain.scrollenabled = true scrollviewmain.showshorizontalscrollindicator = false scrollviewmain.showsverticalscrollindicator = true scrollviewmain.indicatorstyle = uiscrollviewindicatorstyle.white scrollviewmain.settranslatesautoresizingmaskintoconstraints(false) view.addsubview(scrollviewmain)  view.backgroundcolor = background_color   headerview = uiview(frame: cgrectmake(0, 0, screen_width, screen_width / 3)) headerview.backgroundcolor = uicolor.clearcolor() headerview.settranslatesautoresizingmaskintoconstraints(false) headerview.layer.maskstobounds = true  tableviewmain = uitableview() tableviewmain.contentinset = uiedgeinsets(top: 0, left: 0, bottom: 0, right: 0) tableviewmain.scrollindicatorinsets = uiedgeinsets(top: 0, left: 0, bottom: 0, right: 0) tableviewmain.delegate = self tableviewmain.datasource = self tableviewmain.backgroundcolor = uicolor.clearcolor() tableviewmain.backgroundview = nil tableviewmain.opaque = false tableviewmain.separatorcolor = uicolor(rgb: 0x3e3e3e) tableviewmain.indicatorstyle = uiscrollviewindicatorstyle.white tableviewmain.scrollenabled = false tableviewmain.settranslatesautoresizingmaskintoconstraints(false) scrollviewmain.addsubview(tableviewmain) tableviewmain.registerclass(moviestableviewcell.self, forcellreuseidentifier: "moviestableviewcell") tableviewmain.tableheaderview = headerview  let viewdictionary = ["scrollviewmain": scrollviewmain, "tableviewmain": tableviewmain, "headerview": headerview]  let scrollviewmainconstraint_horizontal:nsarray = nslayoutconstraint.constraintswithvisualformat(     "h:|-0-[scrollviewmain]-0-|",     options: nil,     metrics: nil,     views: viewdictionary ) let scrollviewmainconstraint_vertical:nsarray = nslayoutconstraint.constraintswithvisualformat(     "v:|-0-[scrollviewmain]-0-|",     options: nil,     metrics: nil,     views: viewdictionary )  view.addconstraints(scrollviewmainconstraint_horizontal as! [anyobject]) view.addconstraints(scrollviewmainconstraint_vertical as! [anyobject]) 

i think issue table view doesn't have constraints, doesn't know rules follow when screen rotates. don't know constraints want, assuming want table view fill whole scroll view, add constraints similar ones used scroll view (pin leading, trailing, top , bottom space superview).


Comments