快照方法在iPhone 6设备和模拟器上损坏

由于某些未知的原因,iPhone 6仿真器(和设备)上的所有屏幕截图方法似乎都可能存在问题。 每当我打电话给任何截图方法,包括:

snapshotViewAfterScreenUpdates:resizableSnapshotViewFromRect:drawViewHierarchyInRect:

afterScreenUpdates设置为YES,屏幕闪烁。 如果设置为NO,则不会出现闪烁,但是我无法获得所需的function。

除了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 

以下是我的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 makeKeyAndVisible]; return YES; } 

任何帮助将不胜感激!

运行以下代码时,我们看到同样的问题:

 [window drawViewHierarchyInRect:window.bounds afterScreenUpdates:YES]; 

我们目前find的唯一解决scheme是确保应用程序具有适用于iPhone 6和6+的启动图像,然后我们不再闪烁。

继Ryans解决scheme之后,我添加了一个启动屏幕xib(或storyboard),这解决了iPhone 6和6 plus的问题。

所以确保你已经在你的项目设置中设置它,它应该最终看起来像这样:

在这里输入图像说明

这似乎是在苹果方面发生的缩放应用程序(那些没有devise/资产/布局支持iPhone 6/6 +)这个帮助我克服了它: snapshotViewAfterScreenUpdates在iOS 8上的故障

基本上使用: [view.layer renderInContext:UIGraphicsGetCurrentContext()];