ios - Where are constraints updated for size classes? -
i have constraint in interface builder default value , compact width value. have constraint linked iboutlet can constant value in code @ runtime. if run on iphone 4s simulator, in viewdidload
constant default value. neither willtransitiontotraitcollection
or viewwilltransitiontosize
called, @ point constraint updated compact value later on correct. constraint updated uiviewcontroller
? it's not updateviewconstraints
.
update: suggested viewdidlayoutsubviews
, traitcollectiondidchange
methods not constant changed either:
override func viewdidlayoutsubviews() { println("before viewdidlayoutsubviews: \(self.navcontrollerbottomspaceconstraint.constant)") super.viewdidlayoutsubviews() println("after viewdidlayoutsubviews: \(self.navcontrollerbottomspaceconstraint.constant)") } override func traitcollectiondidchange(previoustraitcollection: uitraitcollection?) { println("before traitcollectiondidchange: \(self.navcontrollerbottomspaceconstraint.constant)") super.traitcollectiondidchange(previoustraitcollection) println("after traitcollectiondidchange: \(self.navcontrollerbottomspaceconstraint.constant)") }
output:
before viewdidlayoutsubviews: 20.0 after viewdidlayoutsubviews: 20.0 before viewdidlayoutsubviews: 20.0 after viewdidlayoutsubviews: 20.0 before viewdidlayoutsubviews: 20.0 after viewdidlayoutsubviews: 20.0 before viewdidlayoutsubviews: 20.0 after viewdidlayoutsubviews: 20.0 before traitcollectiondidchange: 20.0 after traitcollectiondidchange: 20.0 before viewdidlayoutsubviews: 0.0 after viewdidlayoutsubviews: 0.0 before viewdidlayoutsubviews: 0.0 after viewdidlayoutsubviews: 0.0
thanks matt , sega-zero pointing me in right direction.
the answer constraint updated in view's first layoutsubviews
after has entered view hierarchy. in view controller can this:
override func viewdidlayoutsubviews() { if self.propertycalculatedfromconstraints == nil && self.view.window != nil { // constraints , sizes valid self.propertycalculatedfromconstraints = self.constraint.constant } super.viewdidlayoutsubviews() } override func viewdiddisappear() { self.propertycalculatedfromconstraints = nil super.viewdiddisappear() }
Comments
Post a Comment