由於某些未知原因,iPhone 6模擬器(和設備)上的所有屏幕截圖方法似乎都可能存在錯誤。每當我打電話任何的截圖方法,包括:在iPhone 6設備和模擬器上損壞的快照方法
snapshotViewAfterScreenUpdates: resizableSnapshotViewFromRect: drawViewHierarchyInRect:
設置爲YES afterScreenUpdates,屏幕閃爍。如果設置爲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
這裏是我的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;
}
任何幫助將不勝感激!