なんとかするから、なんとかなる

エンジニア関係のことを書きます

iOS It’s difficult to animate UIView by themselves when it appeared.

Introduction

This article explains its difficult to animate an UIView by themselves when it appeared.

Conclusion

There two solution for the problem. • Call some animation start method by UIViewController • Observe the didBecomeActive event from a notification.

Detail

UIView have some lifecycle methods and drawing methods as you know.

I tried to set a method that’ll start an animation for the UIView.

But, the methods like a didMoveToWindow etc. is called multi times.

And other method like layoutSubview(), drawRect: is not called when an app come back from background.

If I set an animation with options=.repeat, the animation would be stopped when the app would go to background or execute some segue.

It’s not impossible to set the animation again when it come from the segue.

But, but it’s so difficult to set the animation again when the app come back from background.

That’s why I put my conclusions.