Khaled Ald Khaled Ald - 1 month ago 5
Swift Question

Show view controller with image for 3 seconds

What I want is to show an

UIImageView
for 3 seconds when the user taps home button, after the three second it should go to background mode, how can I do this?

Answer

You have a function in your AppDelegate file called applicationWillResignActive that function will be called when the user hits the home button and let´s say that you would have done what you like, there is the place to put the code BUT Apple WILL reject your app if you try to make the application wait for three seconds before the user goes back to the home screen.

If you still want to try you can in the applicationWilLResingActive class navigate to a view that you have set up and show an image:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "ImageViewController") as! ImageViewController
controller.image = // set the image here that you want to show
self.window?.rootViewController!.present(controller, animated: true, completion: { () -> Void in
})

In your ImageViewController viewDidLoad you show the image.