贡献者:赵大财
博客:https://my.oschina.net/zhaodacaiGitHub:https://github.com/dacaizhao
邮箱: dacai_zhao@163.com QQ:327532817
=============================
DispatchQueue.main.asyncAfter(deadline: .now() + 0.9) { self.currentView.isUserInteractionEnabled = true }
func hideView(afterDelay:CGFloat) { let after = TimeInterval(afterDelay) DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(after * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC),execute: { self.maskview.removeFromSuperview() }) }
DispatchQueue.global().async { //耗时操作 DispatchQueue.main.async { //刷新UI } }
// 创建一个队列组 let group = DispatchGroup() // A任务入组 group.enter() // A任务异步操作 DispatchQueue.global().async(group: group,execute: DispatchWorkItem(block: { sleep(2) print("download task A ...") // 出组 group.leave() })) // B任务入组 group.enter() // B任务异步操作 DispatchQueue.global().async(group: group,execute: DispatchWorkItem(block: { sleep(2) print("download task B ...") // 出组 group.leave() })) // 主线程监听,只有当队列组中没有任务,才会执行闭包。如果多次调用该方法,每次都会去检查队列组中是否有任务,如果没有任务才执行 group.notify(queue: DispatchQueue.main) { print("complete!") } 原文链接:https://www.f2er.com/swift/322584.html