如何在Xcode中添加延迟?
self.label1.alpha = 1.0
//delay
self.label1.alpha = 0.0
Run Code Online (Sandbox Code Playgroud)
我想让它等待大约2秒钟.我读过有关time_dispatch和导入darwin库的内容,但我无法使其工作.那么有人可以一步一步地解释它吗?
您只需编写此代码:
self.label1.alpha = 1.0
let delay = 2 * Double(NSEC_PER_SEC)
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay))
dispatch_after(time, dispatch_get_main_queue()) {
// After 2 seconds this line will be executed
self.label1.alpha = 0.0
}
Run Code Online (Sandbox Code Playgroud)
'2'是你想要等待的秒数
问候
| 归档时间: |
|
| 查看次数: |
11297 次 |
| 最近记录: |