dispatch_after - GCD in Swift?

前端 未结 25 2375
心在旅途
心在旅途 2020-11-21 06:07

I\'ve gone through the iBook from Apple, and couldn\'t find any definition of it:

Can someone explain the structure of dispatch_after?

d         


        
25条回答
  •  温柔的废话
    2020-11-21 06:34

    For multiple functions use this. This is very helpful to use animations or Activity loader for static functions or any UI Update.

    DispatchQueue.main.asyncAfter(deadline: .now() + 0.9) {
                // Call your function 1
                DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
                    // Call your function 2
                }
            }
    

    For example - Use a animation before a tableView reloads. Or any other UI update after the animation.

    *// Start your amination* 
    self.startAnimation()
    DispatchQueue.main.asyncAfter(deadline: .now() + 0.9) {
                    *// The animation will execute depending on the delay time*
                    self.stopAnimation()
                    DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
                        *// Now update your view*
                         self.fetchData()
                         self.updateUI()
                    }
                }
    

提交回复
热议问题