0

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!)

Jackson Egan
  • 2,715
  • 4
  • 18
  • 26

1 Answers1

1

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!

Asif Mujteba
  • 4,596
  • 2
  • 22
  • 38
  • Great! I'll give this a go. Where can I find the image once it's taken? – Jackson Egan Nov 06 '12 at 04:36
  • 1
    once you have the UIImage object, than you can simply use it your code or save it in document directory for later viewing, check [this link](http://stackoverflow.com/questions/2264039/uiimage-saving-image-with-file-name-on-the-iphone) for saving image into a file – Asif Mujteba Nov 06 '12 at 06:45