停止/暂停Swift应用程序的时间段 [英] Stop / Pause swift app for period of time
问题描述
我的应用程序使用多个线程 NSTimer
对象。
My app uses multiple threads of NSTimer
Object.
在一个函数中(随机随机调用,不是固定的延迟),我想让它暂停整个应用程序,暂停 1秒
。我有以下代码:
Within the one function (called randomly at random times, not a fixed delay) I want it to pause the whole app, pause the threads for 1 second
only. I have the following code:
[self performSelector:@selector(subscribe) withObject:self afterDelay:3.0 ];
这是客观的C,我试着把它翻译成Swift:
Which is objective C, and I tried translating it into Swift like this:
self.performSelector(Selector:changeColourOfPage(), withObject: self, afterDelay: 1.0)
但我得到的错误参数'waitUntilDone'在调用
缺少参数和当我把它,它说它想要参数 modes
但是当我把它放在额外的参数模式
。
But I am getting the error Missing argument for parameter 'waitUntilDone' in call
and when I put that in, it says it wants the argument modes
but when I put that in it says Extra argument modes
.
我不知道如何暂停应用程序及其所有的线程几秒钟,然后像正常一样继续?
I cannot figure out how to pause the app and all it's threads for a couple of seconds, and then carry on like normal?
任何想法?
推荐答案
performSelector方法在Swift中不可用。您可以使用dispatch_after获取延迟功能。
The performSelector methods aren't available in Swift. You can get the delay functionality by using dispatch_after.
let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(NSEC_PER_SEC * 1))
dispatch_after(delayTime, dispatch_get_main_queue()){
changeColourOfPage()
}
这篇关于停止/暂停Swift应用程序的时间段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!