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!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top