2

I'm considering building my first iOS app in the following months. This is going to a hybrid app:

https://fanmixco.github.io/toastmasters-timer-material-design/

At this point is fully migrated to Android and Windows 10. However, one of my greatest challenges in Android was the screen rotation:

This situation was quite complex to handle since each time my app was rotated the activity was destroyed and I needed to add several workarounds in order to keep the app running, restoring the previous states, colors, stop the timers before the rotation because they kept running in background, etc.

I didn't experience anything similar in Windows 10 and I'd like to know if the iOS View Life-Cycle behaves closely, are the views destroyed during the rotation of any device? Because my workarounds are reusable, but they add certain complexity and reduce performance.

These are some of the sites that I read:

Nevertheless, I haven't found anything precise about this topic.

P.S.

  • I'd like to find if there is any documentation or examples since I invested a considerable amount of time in the Android Specific Situation to avoid finding at the last minute that I needed to reuse the workarounds.
  • I'm not sure if this question should be here or in Software Engineering. If I should move it just let me know and I'm going to do it.
Federico Navarrete
  • 3,069
  • 5
  • 41
  • 76
  • Sry I couldnt understand what you meant by destroy here ? Pls specify your issue, even example will be more better. – dahiya_boy Apr 23 '19 at 05:36
  • @dahiya_boy, I mean if you rotate the app, is the app still running? Because if you rotate an app in Android, the activity is destroyed and stops working, the states are not exactly preserved in most of the cases; especially in a Hybrid app because the timers, etc. Are lost somewhere and they create very inconvenient situations that you need to handle. – Federico Navarrete Apr 23 '19 at 05:39
  • Don't know abt hybrid or android but in iOS there is nothing like that. You will be on same position/state. There may be issue in the UI layout but it depends how you are handling it. Just check this youtube -> https://www.youtube.com/watch?v=VLh0RIQmCr4 – dahiya_boy Apr 23 '19 at 05:43
  • You have changed your question multi-times. First clear-out what's your issue. – dahiya_boy Apr 23 '19 at 05:53
  • Hi @dahiya_boy, the question hasn't changed at all, you can check the history: are the views destroyed during the rotation of any device? I have updated to avoid any possible misunderstanding in other points. It's even in bold since the beginning. – Federico Navarrete Apr 23 '19 at 06:51
  • https://stackoverflow.com/questions/26069874/what-is-the-right-way-to-handle-orientation-changes-in-ios-8 – Dalija Prasnikar Apr 23 '19 at 08:56
  • https://stackoverflow.com/questions/38894031/swift-how-to-detect-orientation-changes/52636500 – Dalija Prasnikar Apr 23 '19 at 08:56
  • Hi @DalijaPrasnikar thanks for your answers, but none of them is answering my question since I don't want to know how to handle the rotation of the screen, I'm aware that there should be some events to know if it's landscape or portrait. I want ot know is the screen recreated after it changes? Or just readjust like when you use responsive web design? Because a website adapts and is not recreated each time you change the pixels while in Android any small change it recreates the entire view. – Federico Navarrete Apr 23 '19 at 09:21
  • That is why I posted them as comments and I didn't closed your question as a duplicate. You already have the answer that answers your question - and linked questions answer what happens and how to handle orientation changes. I though it would be obvious - **iOS does not destroy the view upon rotation** - depending on your layout you may need to handle orientation change to adjust your UI, but it is not mandatory. – Dalija Prasnikar Apr 23 '19 at 09:28

1 Answers1

6

When the screen is rotated the views are not destroyed. However it is re-laid out/re-drawn based on the constraints on the view. But this won’t destroy properties or mess with state on the view.

Sergio
  • 2,346
  • 2
  • 24
  • 28
Justin
  • 1,318
  • 9
  • 12
  • Thanks for your answer. Do you have some documentation? Or examples? Because personally, this is quite crucial point in my case since I invested many months in the Android situation and it was hard to debug it. Thanks. – Federico Navarrete Apr 23 '19 at 05:41
  • @FedericoNavarrete When the screens rotated `setNeedsLayout` will be called on the view. https://medium.com/@abhimuralidharan/ios-swift-setneedslayout-vs-layoutifneeded-vs-layoutsubviews-5a2b486da31c Has some information about it and others. I don’t know of any exact documentation just personal experience that it won’t be destroyed. A simple way to test it is to create a view in a new application and rotate the screen in the simulator - if you have access to Xcode. – Justin Apr 23 '19 at 05:44