Swift: How to resize UIView and keep contents centered? -
i have uiview ("myuiview") in viewcontroller ("mainview") has uilabel ("myuilabel") inside, centered vertically autolayout constraints. i'm animating uiview change height.
originally, thought auto layout keep track of animation/change , keep uilabel centered, instead uilabel acts though constrained top of uiview.
the uilabel isn't in animation code itself. code reference:
uiview.animatewithduration(currentanimationtime, delay: 0.0, options: .curveeaseout, animations: { self.myuiview.frame = cgrectmake(0, self.mainview.frame.height * 0.2, self.mainview.frame.width, self.mainview.frame.height * 0.6 ) }, completion: nil)
how can increase uiview's height , keep uilabel entered vertically? need add directly affects uilabel itself, or going resize (cgrectmake) wrong?
i have had luck calling layoutifneeded
on animated view inside animation.
it preferable create outlet height constraint of view , set constant
of constraint rather constructing cgrect
. change constant outside animation demonstrated in this answer.
Comments
Post a Comment