简体   繁体   English

iOS Swift应用程序方向更改非常慢; iOS设备更改方向时会发生什么?

[英]ios swift app orientation change very slow; what happens when iOS device changes orientation?

I have a UIViewController that contains a UIScrollView, into which I build all my content for display. 我有一个包含UIScrollView的UIViewController,我将所有内容都构建到其中。 I do this because the content is dynamic and depends on data stored in the database. 我这样做是因为内容是动态的,并且取决于数据库中存储的数据。

When I change orientation on an iPhone or in the simulator it takes a long time to perform the change (depending on the data for the display it can be up to 40 seconds). 当我在iPhone或模拟器上更改方向时,执行更改需要花费很长时间(取决于显示数据,最长可能需要40秒)。

If I just launch the same controller it takes only a few seconds (it has an overlay and progress indicator so the user knows it's thinking). 如果我只是启动同一控制器,则只需几秒钟(它具有覆盖和进度指示器,因此用户知道它在想什么)。

Why should the orientation take so long? 定向为什么要花这么长时间? What actually happens when an orientation change occurs? 当方向发生变化时,实际发生了什么?

How do you load the data from your database, synchronously or asynchronously? 如何从数据库中同步或异步加载数据? You should load it asynchronously if you want a better responsiveness from your app. 如果您希望应用程序具有更好的响应能力,则应该异步加载它。

Also, if the database is accessed synchronously from the main thread, then where is located that code that loads the data: somewhere in 'viewDidLoad', 'viewDidLayoutSubviews', etc.? 另外,如果从主线程同步访问数据库,那么加载数据的代码位于何处:“ viewDidLoad”,“ viewDidLayoutSubviews”等中的某处? I suspect that that loading code runs multiple times when the orientation of the device changes, so you can try to put a breakpoint there and see what exactly happens... 我怀疑当设备方向改变时,加载代码会运行多次,因此您可以尝试在此处放置一个断点,看看到底发生了什么...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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