ios - First time animating is glitchy -


i animating view gradientview in/out using following:

func hideorshowgradientview(hide: bool) {     uiview.animate(withduration: 0.4, animations: {         self.gradientview.ishidden = hide     }) } 

this works well, on first time, there no animation. appears. on second , third time works wonderfully. i've tried calling animate block on main thread no luck there. why animation failing occur on first , first time around? should using animation method?

have tried calling self.view.layoutifneeded(). forces view , it's subviews complete of it's pending animations immediately, might interfering animation. can use this:

func hideorshowgradientview(hide: bool) {     self.view.layoutifneeded()     uiview.animate(withduration: 0.4, animations: {         self.gradientview.ishidden = hide         self.view.layoutifneeded()     }) } 

apple recommends calling layoutifneeded() twice, once before animation block forces redraw on view , it's subviews, , completes pending animations on view without waiting next update cycle, , call second time inside animation block make sure animation changes applied immediately.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -