gpt4 book ai didi

即使在单独的线程上,Swift 也无法与页面交互

转载 作者:行者123 更新时间:2023-11-30 13:25:34 26 4
gpt4 key购买 nike

我刚开始使用单独的线程。我想我做错了。我试图让这个动画发生,但允许用户在其发生时与页面交互。

这是我的代码

let priority = DISPATCH_QUEUE_PRIORITY_DEFAULT
dispatch_async(dispatch_get_global_queue(priority, 0)) {
UIView.animateWithDuration(3.0, animations: {
self.backgroundView.layer.backgroundColor = UIColor(red: 25.0/255.0, green: 25.0/255.0, blue: 25.0/255.0, alpha: 1.0).CGColor
})

dispatch_async(dispatch_get_main_queue()) {
self.backgroundView.layer.backgroundColor = UIColor(red: 25.0/255.0, green: 25.0/255.0, blue: 25.0/255.0, alpha: 1.0).CGColor
}
}

最佳答案

感谢@Rob 的回答。

Animations must take place on the main thread. If you want to allow user interaction, use the .AllowUserInteraction option in animationWithDuration:delay:options:animations:completions

关于即使在单独的线程上,Swift 也无法与页面交互,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37242583/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com