gpt4 book ai didi

ios - 第一个从计时器完成后如何在下面的函数中调用函数

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:58:37 25 4
gpt4 key购买 nike

这是我的简单形式的流程。我仍然需要在 #2 完成运行后调用 decisionMaker() 直到时间到了,并将用于测量的全局变量带到 decisionmaker() 以进行案例测试

TestButtonTAPPED() 并调用:

  1. 记录定时器()
  2. 收集输入()

  3. 选择器:levelTimerCallback()

  4. 决策者()

    // 1.
    func recordTimer() {
    /* After 10 seconds, let's stop the recording process */
    let delayInSeconds = 10.0
    let delayInNanoSeconds = DispatchTime.now() + Double(Int64(delayInSeconds * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)

    DispatchQueue.main.after(when: delayInNanoSeconds, execute: {
    self.soundRecorder!.stop()
    self.handBtn.isHidden = false
    })

    }

    // 2.
    func gatherInput() {
    levelTimer = Timer.scheduledTimer(timeInterval: 0.9, target: self, selector: #selector(DBListener.levelTimerCallback), userInfo:nil, repeats: true)
    }

    //3.
    func levelTimerCallback() {
    if soundRecorder.averagePower(forChannel: 0) > -30
    {
    // Do gathering for vaiables
    }
    }


    // 4.
    func decisionMaker() {
    // case statments here for final measurement
    }



    @IBAction func handTapped(_ sender: UIButton) {

    clearGlobalVariablesOnTap()
    listner()
    soundRecorder.record()
    recordTimer()
    dbListener.gatherInput()

    }

最佳答案

@IBAction func handTapped(_ sender: UIButton) {
clearGlobalVariablesOnTap()
listner()
soundRecorder.record()
recordTimer()
}

func recordTimer() {

//As soon as this method is called this portion will get executed
dbListener.gatherInput()

/* After 10 seconds, let's stop the recording process */
let delay = 10.0
let delayInSeconds = DispatchTime.now() + DispatchTimeInterval.seconds(delay)


//After 10 seconds this block will execute
DispatchQueue.main.after(when: delayInSeconds, execute: {
self.soundRecorder!.stop()
self.handBtn.isHidden = false
self.levelTimer.invalidate = true
self.decisionMaker()
})

}

func gatherInput() {
levelTimer = Timer.scheduledTimer(timeInterval: 0.9, target: self, selector: #selector(DBListener.levelTimerCallback), userInfo:nil, repeats: true)
}

func levelTimerCallback() {
if soundRecorder.averagePower(forChannel: 0) > -30
{
// Do gathering for vaiables
}
}


func decisionMaker() {
// case statments here for final measurement
}

关于ios - 第一个从计时器完成后如何在下面的函数中调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38749322/

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