我必须在点击 UIAlertView 的" ok" 按钮时截取屏幕截图。屏幕截图应包含警报视图以及设备屏幕上显示的所有其他视图。我试图使用下面的代码实现截图捕获的功能。但我拍摄的截图是一张空白图片。 请为此问题提供解决方案。
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow] ;
CGRect rect = CGRectMake(0, 64, 1024, 704);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, -rect.origin.x, -rect.origin.y);
[keyWindow.rootViewController.view drawViewHierarchyInRect:keyWindow.rootViewController.view.bounds afterScreenUpdates:YES];
UIImage *screenShotImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSFileManager *fileManager = [NSFileManager defaultManager];
NSData *myImageData = UIImagePNGRepresentation(screenShotImage);
[fileManager createFileAtPath:@"/Users/mac/Desktop/myimage.png" contents:myImageData attributes:nil];