在我的应用中,我有一个计时器,最长可长达5分钟.用户可以将元素添加到数组中,从而将计时器重置为5分钟.当计时器计数城镇时,还有一个UIView会将其宽度按计时器的比例从视图的100%更改为视图的0%.
In my app I have a timer that can be up to 5 minutes long. The user can add an element to an array which resets the timer to 5 minutes. When the timer counts town, there's also a UIView which changes its width from 100% of the view to 0% of it in proportion to the timer.
我想在后台线程上运行计时器,以避免由于其他UI事件发生而导致计时器启动延迟.
I'd like to run my timer on a background thread to avoid a delay in the timer starting due to other UI events happening.
是否可以在后台线程中运行一个计时器,该计时器调用的关联函数可以更新UI中的标签或视图宽度,而不会导致线程问题/崩溃?到目前为止,我还无法正常工作.
Is it possible to have a timer run in a background thread whose associated function that the timer calls updates a label or a view width in the UI without threading issues/crashing? So far I haven't been able to get this working.
推荐答案只需从主线程更新UI.
Just need to update your UI from the main thread.
... dispatch_async(dispatch_get_main_queue(), { () -> Void in // perform view resizing }) ...更多推荐
在后台线程中使用计时器更新UI
发布评论