I'm trying to cover up some changes that take place in my view during the transition between viewWillAppear
and viewDidAppear
and would like to take a screen shot during or immediately before viewWillDisappear
and then display it during viewWillAppear
.
I know that a few years ago Apple allowed us to use UIGetScreenImage
, but that is no longer the case. What is the best way to grab an image of the screen for these purposes now that they have taken away UIGetScreenImage
?
(Any further advice on how to accomplish the rest of my goal would also be appreciated!)
You can get the screen shot of the screen by calling -renderInContext method of CALayer on your top view like this.
UIGraphicsBeginImageContext(self.view.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.view.layer renderInContext:context];
UIImage *imgScreenShot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
here, imgScreenShot is the desired image. enjoy programming!