过渡到通过计时器查看

时间:2019-05-28 14:49:25

标签: ios swift uiview nstimer

我需要使用计时器来实现向另一个plot(df1[,1],df1[,2], log = "y", type ="l", col = "orange", xlim=range(df1[,1], df2[,1]), ylim=range(df1[,2], df2[,2])) lines(df2[,1], df2[,2], col = "blue") 的平滑过渡。

例如,当我单击“开始”按钮并经过15秒钟后,就会自动过渡到另一个View

Current Views

1 个答案:

答案 0 :(得分:1)

在开始按钮操作中,使用递增计数器变量启动计时器。在计时器执行块中,如果计数达到15,则使计时器无效并导航到下一个视图控制器

@objc func startBtnAction(_ sender: UIButton) {
    var count = 0
    let target = 15
    Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { [weak self] timer in
        self?.label.text = String(format: "%02d:%02d", count/60,count%60)
        if count == target {
            timer.invalidate()
            self?.performSegue(withIdentifier: "NextScreen", sender: self)
        } else {
            count += 1
        }
    }
}