简体   繁体   中英

Wait for autolayout to perform UIView animation

I have an UIView that is loaded from its .xib file and I'd like to perform the animation right when the view is shown.

I want to copy an ImageView and perform the animation using that copy, the problem is that since I'm calling the animation within willMove(toWindow:) method, the copied ImageView frame is created before the autolayout resulting in a weird behavior.

I've tried calling layoutIfNeeded() before the animation but with this, the animation isn't performed.

Thanks in advance!

right when the view is shown? try managing the UIView via a UIViewController and perform the animation in func viewDidAppear(_ animated: Bool) inside your viewController

an example here below how to insert the uiView managed in a new UIViewController in current viewController's view:

self.view.addSubview(myNewViewControler.view)

then in the NewViewController you can call back the current presented viewController in the viewDidAppear via delegate and finally perform animation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM