我的代码适用于普通设备,但在视网膜设备上会产生模糊图像.
有人知道我的问题的解决方案吗?
+ (UIImage *) imageWithView:(UIView *)view
{
UIGraphicsBeginImageContext(view.bounds.size);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
Run Code Online (Sandbox Code Playgroud) 由于某些未知原因,iPhone 6模拟器(和设备)上的所有屏幕截图方法似乎都存在可能的错误.每当我调用任何截图方法时,包括:
snapshotViewAfterScreenUpdates:resizableSnapshotViewFromRect:drawViewHierarchyInRect:
将afterScreenUpdates设置为YES,屏幕闪烁.如果设置为NO,则不会出现闪烁,但我无法获得所需的功能.
除了iPhone 6和6+之外,这些方法在所有其他模拟器中都适用于iOS7.1和iOS8.
奇怪的是,如果我使用故事板开始一个全新的项目并尝试类似的代码,我无法重现闪烁.我使用非故事板项目附加了闪烁的GIF:

这是非常简单的视图控制器:
@implementation TestSnapshotController
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Snap" style:UIBarButtonItemStylePlain target:self action:@selector(_snap)];
self.blueView = [UIView new];
self.blueView.backgroundColor = [UIColor blueColor];
self.blueView.frame = CGRectMake(100.0f, 100.0f, 100.0f, 100.0f);
[self.view addSubview:self.blueView];
}
- (void)_snap
{
[self.blueView snapshotViewAfterScreenUpdates:YES];
}
@end
Run Code Online (Sandbox Code Playgroud)
这是我的AppDelegate以防万一:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
TestSnapshotController *testVC = [TestSnapshotController new];
UINavigationController *rootNavVC = [[UINavigationController alloc] initWithRootViewController:testVC];
self.window.rootViewController = rootNavVC;
self.window.backgroundColor = [UIColor whiteColor];
[self.window …Run Code Online (Sandbox Code Playgroud)