我正在尝试获取用户看到的整个屏幕的图像。以下代码应该可以工作,但它只能在模拟器中工作。我需要做什么才能让它在运行 iOS 8.1 的设备上运行?
UIView *snapshot = [[UIScreen mainScreen] snapshotViewAfterScreenUpdates:YES];
CGSize outputSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
UIGraphicsBeginImageContextWithOptions(outputSize, NO, 0);
[snapshot drawViewHierarchyInRect:CGRectMake(0.0, 0.0, outputSize.width, outputSize.height) afterScreenUpdates:YES];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
很高兴尝试替代策略,但关键是我想要用户看到它的样子 - 键盘和所有。
干杯
最佳答案
UIGraphicsBeginImageContextWithOptions(CGSizeMake(CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame)), NO, 1.0f);
[self.view drawViewHierarchyInRect:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame)) afterScreenUpdates:NO];
UIImage *snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
关于ios - UIScreen 上的 snapshotViewAfterScreenUpdates 在设备上提供空白快照,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27797360/