Delay Actions in Swift

后端 未结 4 598
长情又很酷
长情又很酷 2020-12-24 11:58

I want to make an Activity Indicator start animating and then stop after one second.

So does anyone know how I could do that?

class stuff {
@IBOutlet         


        
4条回答
  •  一个人的身影
    2020-12-24 12:48

    Here is a cleaner and more expressive code to do this using Swift 3.1 and Grand Central Dispatch:

    Swift 3.1:

    indicator.startAnimating()
    
    // Runs after 1 second on the main queue.
    DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1) ) { 
        indicator.stopAnimating()
    }
    

    Also .seconds(Int), .microseconds(Int) and .nanoseconds(Int) may be used for the time.

提交回复
热议问题