LoginSignup
3
3

More than 5 years have passed since last update.

UIAlertControllerを時間差で閉じる方法

Posted at

2秒後に自動で閉じる

Swift
let alert: UIAlertController = UIAlertController(title: "", message: "Alert", preferredStyle: .Alert)
self.presentViewController(alert, animated: true) { () -> Void in
            let delay = 2.0 * Double(NSEC_PER_SEC)
            let time  = dispatch_time(DISPATCH_TIME_NOW, Int64(delay))
            dispatch_after(time, dispatch_get_main_queue(), {
                self.dismissViewControllerAnimated(true, completion: nil)
            })
        }

意外と簡単便利。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3