简体   繁体   English

Swift-在后台加载ViewController

[英]Swift - Load ViewController in background

i have a View Controller with a huge stack of Images in an Array. 我有一个视图控制器,阵列中有大量图像。 When i press the Button that takes me to View Controller it takes about 8-15 Seconds to load. 当我按下将我带到View Controller的按钮时,加载大约需要8-15秒。 Now I want to make a Loading screen so every time the app start, the View controller should be loaded in background. 现在,我要创建一个“正在加载”屏幕,以便每次启动应用程序时,都应在后台加载View控制器。

How can I do this? 我怎样才能做到这一点?

Thanks! 谢谢!

The best way to do that, relating to the final user experience, is using an Activity Indicator . 与最终用户体验有关的最佳方法是使用“ 活动指示器”

You should add it normally to your ViewController and relating it to your swift viewController'file. 您通常应将其添加到ViewController中,并将其与快速的viewController'文件相关联。

When the loading will start, you must start to "spin" your activity indicator: in this way the user "understand" that "something will be loaded in a while". 当加载开始时,您必须开始“旋转”您的活动指示器:通过这种方式,用户“理解”“将在一段时间内加载某些内容”。

When the loading will be finished, you must just make it hidden . 加载完成后,您只需将其隐藏即可

Moreover, if you want to be sure that images will be added after the loading of the view controller itself, load them through the viewWillAppear method, NOT viewDidLoad ! 此外,如果要确保在加载视图控制器本身之后添加图像,请通过viewWillAppear方法而不是viewDidLoad加载它们!

Hope this will help you for background queue and main queue operation !!!! 希望这可以帮助您进行后台队列和主队列操作!

func bgQueue(queueName: String, completion codeBlock: @escaping ((Bool) -> Void)) {

        DispatchQueue.global(qos: .background).async {
            codeBlock(true)
        }
    }

func mainQueue(codeBlock: @escaping ((Bool) -> Void)){
        DispatchQueue.main.async {
            codeBlock(true)
        }
    }

don't load image in ViewDidLoad() 不要在ViewDidLoad()中加载图像

use this to load image 用它来加载图像

DispatchQueue.main.async {

}

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

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