-4

I am creating a small project such that after pressing a button which will take me to the next view controller using the navigation controller - can i delay the function to execute the navigation controller after some time

i am using this code-

import UIKit

class ViewController: UIViewController
{
   @IBAction func enterButtonPressed(_ sender: UIButton)
   {
       let vc = storyboard?.instantiateViewController(withIdentifier: "ViewController2") as! ViewController2
       self.navigationController?.pushViewController(vc, animated: true)
   }

   override func viewDidLoad()
   {
      super.viewDidLoad()
   }

   override func didReceiveMemoryWarning() 
   {
      super.didReceiveMemoryWarning()
   }

}
Barkermn01
  • 6,781
  • 33
  • 83
Lakshay Kalra
  • 317
  • 3
  • 14

2 Answers2

3

Suppose sender.tag holds the duration which is 0 for proceed , 5 or 10

var playTimer:Timer?

//

@IBAction func btnClicked(_ sender:UIButton) {

    playTimer?.invalidate()

    playTimer = Timer.scheduledTimer(withTimeInterval: TimeInterval(sender.tag), repeats: false, block: { (T) in

        // play the audio

    })
}
Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87
0

Try this one

var timeLimit = 5.0
DispatchQueue.main.asyncAfter(deadline: .now() + timeLimit, execute: {
    //Play your audio here
    //Audio will play after 5 seconds here
})
Manish Mahajan
  • 2,062
  • 1
  • 13
  • 19
  • Actually asyncAfter is not guaranteed to be called at a specific time, it is guaranteed to be run after specified time, not sure this is correct answer – mihatel Jun 27 '18 at 12:32