2014-09-20 62 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()];

相關問題