Reputation: 241
So I have a button on screen that is connected through storyboards with a push Segway. I press the button and it goes to the next view controller.
If I wanted to slow the transition up by say 1-2 seconds how would I go about doing that?
Upvotes: 2
Views: 803
Reputation: 6800
You can create a method in your first view controller that uses the performSegueWithIdentifier method after a delay.
You then connect the button on the view controller to that method.
Code example:
Storyboard
Here I have the initial view controller with a manual segue to the second view controller.
I've connected the Fire Method button to an IBAction on the initial view controller, with this code:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// This method is connected to the Fire Method button
@IBAction func fireMethodBttnTouched(sender: AnyObject) {
let delay = 1 * Double(NSEC_PER_SEC)
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay))
dispatch_after(time, dispatch_get_main_queue()) { () -> Void in
self.performSegueWithIdentifier("showSecondViewController", sender: self)
}
}
}
You can adjust the delay constant as needed.
Upvotes: 3