2014-09-20 59 views
18

由于某些未知原因,iPhone 6模拟器(和设备)上的所有屏幕截图方法似乎都可能存在错误。每当我打电话任何的截图方法,包括:在iPhone 6设备和模拟器上损坏的快照方法

snapshotViewAfterScreenUpdates: resizableSnapshotViewFromRect: drawViewHierarchyInRect:

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

这些方法在除iPhone 6和6+之外的所有其他模拟器中均可与iOS7.1和iOS8兼容。

奇怪的是,如果我使用故事板开始一个全新的项目并尝试类似的代码,我不能再现闪烁。我重视使用我的非情节串连图板项目闪烁的GIF:

enter image description here

这里是非常简单的视图控制器:

@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; 
} 

任何帮助将不胜感激!

回答

5

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

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

是我们迄今发现的唯一的解决办法是,以确保尺寸为iPhone 6和应用程序已经启动图像6+然后我们不再闪烁。

2

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

因此,请确保您有它在您的项目设置中设置,它最终应该看起来像这样:

enter image description here

0

这似乎是在规模应用出现在苹果的一侧的bug(这些有没有设计/资产/布局介绍iPhone 6/6 +) 支持这一个帮助我得到了它: snapshotViewAfterScreenUpdates glitch on iOS 8

主要采用: [view.layer renderInContext:UIGraphicsGetCurrentContext()];

相关问题