문제

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