我正在寻找一种在包含顶部状态栏的 iPhone 上捕获屏幕截图的方法,我目前正在使用以下代码:
UIGraphicsBeginImageContext(self.view.bounds.size); //self.view.window.frame.size
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
上面的代码成功截取了 iPhone UIView 的屏幕截图,但不包括顶部状态栏(取而代之的是一个空白的 20px 空间)。