snapshotViewAfterScreenUpdates glitch on iOS 8

那年仲夏 提交于 2019-12-31 09:21:30

问题


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.


回答1:


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



回答2:


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)




回答3:


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.



来源:https://stackoverflow.com/questions/25873234/snapshotviewafterscreenupdates-glitch-on-ios-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!