Swift 4 获取定时定时器的当前时间间隔

标签 swift timer

<分区>

我正在为我的应用程序使用预定计时器,例如:

contentTimer = Timer.scheduledTimer(timeInterval: 30, target: self, selector: #selector(HandleSendContentTime), userInfo: nil, repeats: true)

它运行良好,但我也想在 viewDisappearing 时获取当前 timeInterval

override func viewWillDisappear(_ animated: Bool) {
    //do something here with time interval

    contentTimer.invalidate()
}

有没有办法在使它失效之前获取当前的 timeInterval 值。

最佳答案

您可以使用“contentTimer.fireDate.timeIntervalSince(Date())”获取当前时间间隔。

关于Swift 4 获取定时定时器的当前时间间隔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49257854/

相关文章:

ios - WatchKit 2.0 检测何时收到 APNS

ios - 当我在 iOS 中滑动进行行操作时,图像从 UIImageView 中出来

c# - 如何以编程方式触发计时器滴答?

C# : start up an application on specific time

ios - dyld : Symbol not found: _OBJC_CLASS_$_Reachability, Xcode 11 崩溃

swift - 重定向 uri 在导航到 oauth url 时导致问题

javascript - JS OOP - 由对象创建多个计时器,但只有一个有效

opengl - 如何在顶点着色器中使用计时器在 OpenGL 中设置点大小的动画

iOS通知-对象参数可以是任意对象吗?

javascript - 单击按钮后显示倒计时器