7

我正在尝试获取用户看到的整个屏幕的图像。以下代码应该可以工作,但它只能在模拟器中工作。我需要做什么才能让它在运行 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();

很高兴尝试替代策略,但关键是我想要它,因为用户看到它 - 键盘和所有。

干杯

4

1 回答 1

1
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();
于 2015-01-06T11:28:12.243 回答