【发布时间】:2015-04-13 23:25:47
【问题描述】:
我尝试了两种不同的方法来创建屏幕截图,但不幸的是它们不能按我的需要工作,我有一个 RMMapView 在屏幕截图上是空白的。当我在我的设备上手动创建快照时,它可以完美运行,并且地图视图在屏幕上。所以我想以编程方式实现相同的结果。正如我尝试的那样,有可能吗?或者这样做的正确方法是什么? (重现该类型的屏幕截图)
- (UIImage *) takeScreenshot {
//1. version
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, [UIScreen mainScreen].scale);
[self.view drawViewHierarchyInRect:self.view.bounds afterScreenUpdates:YES];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
//2. version
UIGraphicsBeginImageContext(self.view.bounds.size);
CGContextRef context=UIGraphicsGetCurrentContext();
[self.view.layer renderInContext:context];
UIImage *image=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
【问题讨论】:
-
什么时候调用takeScreenshot?
-
@MustafaIbrahim 点击按钮后。
-
点击按钮时地图是否在屏幕上?
-
@MustafaIbrahim 当然。
标签: ios objective-c uiimage