snapshotViewAfterScreenUpdates glitch on iOS 8
Asked Answered
T

3

21

I've noticed running this would cause view (or main window, not sure) to resize for a moment, when running on iPhone 6/6+ simulator scaled from iPhone 5 layout (without passing launch image for iPhone 6/6+):

[self.view snapshotViewAfterScreenUpdates:YES];

Any idea how to make it work when you can't pass 'NO' there?

Update (Jul 13th):
Does not seem to reproduce on iOS 8.4 anymore.

Thiele answered 16/9, 2014 at 15:49 Comment(8)
Have the same problem, let me know if you've figured a solution.Hampden
Unfortunately this has been a bug for a while. It impacts iOS 7 as well (when you run an iPhone app on iPad). See here: openradar.io/15909891Manhour
@anon I've ended up adjusting layouts for iPhone 6/6+. On native device resolutions the issue does not reproduceThiele
This solved my problem: https://mcmap.net/q/660991/-snapshot-methods-broken-on-iphone-6-device-and-simulatorCouperin
Well, yeah, while that solves the problem, adding a launch screen makes app run in native (not scaled) mode.Thiele
Looks like it has been fixed in iOS 8.4. Can you confirm?Diseased
Geva, yep, can't seem to reproduce.Thiele
It solve my problem so i have upvote for your good postThisbee
H
13

Since it seemed like an Apple/API problem, I just decided to not use that method when I need to pass a "YES."

You can just take a screenshot (UIImage) of your view and place it in a UIImageView to act as the "UIView" you used to get from the snapshot method.

Here's a link for code: How to capture UIView to UIImage without loss of quality on retina display

#import <QuartzCore/QuartzCore.h>

+ (UIImage *) imageWithView:(UIView *)view
{
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage * img = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return img;
}
Hampden answered 24/9, 2014 at 19:20 Comment(5)
Unfortunately this does not work. It does the same as passing "NO" as a parameter to snapshotViewAfterScreenUpdates - which is not what @Dannie P is trying to do.Manhour
I disagree because passing a "NO" did not do the same thing as taking a snapshot using UIImage. Passing a "NO" gave me a blank view. There's no way to know whether it does the same thing without seeing the code. I do agree that it's not a complete replacement. I had to make some adjustments to my autolayout in IB to make less adjustment during the loading of the view because the UIImage snapshot takes it before constraints are properly adjusted.Hampden
I meant when you pass "NO", recent changes are not incorporated to the view, and it's the same when you just capture. Having the ability to integrate recent changes to the capture is sometimes very important, e.g. when you use this inside a custom transition (animateTransition...).Manhour
@anon screenhotting might be an answer in some cases. It would not help though if you e.g. try to do that in viewDidLoad to animate some transitionThiele
It solve my big problem . Great answer. I have upvote for your good postThisbee
L
3

I just had this issue.

The reason was that I didn't have launch images suitable for iPhone 6 nor 6 plus. Another issue I saw because of this non-existing image was that I got size for iPhone 5 when I asked the screen size bounds like this:

CGSize screenSize = [[UIScreen mainScreen] bounds].size;

When I fixed these images, this issue was fixed.

P.S - it should work whether you use asset catalog or nib file for the launch image. In the asset catalog you should add the 'V' in right side (Attributes Inspector) under iOS 8 and later, and set images for 'Retina HD 5.5' (for 6 plus) and 'Retina HD 4.7' (for iPhone 6)

Louettalough answered 16/11, 2014 at 15:38 Comment(2)
I don't see why this isn't the accepted answer. It works like a charm now! ThanksFeingold
DZenBot, the original goal was to make it work with iPhone 5th layout on iPhone 6 (scaled mode). The reason for that was a need to have a workaround before layout constraints has been fixed to support larger iPhones' sizes.Thiele
T
1

It seems like @anon and @PJC are right and that's a UIKit's bug. It sometimes can be workarounded by [view.layer renderInContext:UIGraphicsGetCurrentContext()]

At this point I've solved the problem for myself by manually adjusting layouts for iPhone 6/6+, as on native device resolutions the issue does not reproduce.

Thiele answered 1/10, 2014 at 10:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.