Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Snapshot methods broken on iPhone 6 device and simulator

For some unknown reason there seems to be a possible bug with all screenshot methods on the iPhone 6 simulator (and device). Whenever I call any of the screenshot methods including:

snapshotViewAfterScreenUpdates: resizableSnapshotViewFromRect: drawViewHierarchyInRect:

with afterScreenUpdates set to YES, the screen flickers. If set to NO, then no flicker occurs, but I am unable to get the functionality that I need.

These methods work fine with both iOS7.1 and iOS8 in all other simulators except for the iPhone 6 and 6+.

Strangely enough, if I start a brand new project using storyboards and try similar code I can't reproduce the flicker. I have attached a gif of the flicker using my non-storyboard project:

enter image description here

And here is the very simple view controller:

    @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

And here is my AppDelegate just in case:

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

Any help would be greatly appreciated!

like image 580
Danny Avatar asked Sep 20 '14 17:09

Danny


1 Answers

We are seeing this same issue when running the following code:

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

The only solution that we have found so far is to make sure that the application has launch images sized for the iPhone 6 and 6+ and then we no longer are getting the flickering.

like image 115
Ryan C. Payne Avatar answered Oct 09 '22 01:10

Ryan C. Payne