在iPhone 6设备和模拟器上的快照方法。

时间:2021-07-17 00:01:51

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:

不知什么原因,iPhone 6模拟器(和设备)上的所有截图方法似乎都有漏洞。无论何时我调用任何截图方法,包括:

snapshotViewAfterScreenUpdates: resizableSnapshotViewFromRect: drawViewHierarchyInRect:

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.

当afterScreenUpdates设置为YES时,屏幕闪烁。如果设置为NO,则不会出现闪烁,但我无法获得所需的功能。

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

除了iPhone 6和6+之外,这些方法在所有其他模拟器中都适用于iOS7.1和iOS8。

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:

奇怪的是,如果我用故事板启动一个全新的项目并尝试类似的代码,我就不能复制闪烁。我使用我的非故事板项目附加了一个闪烁的gif:

在iPhone 6设备和模拟器上的快照方法。

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:

这是我的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;
}

Any help would be greatly appreciated!

如有任何帮助,我们将不胜感激!

3 个解决方案

#1


5  

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.

到目前为止我们发现的唯一解决方案是确保应用程序为iPhone 6和6+启动图像大小,然后我们就不再有闪烁的图像了。

#2


2  

Following on from Ryans solution, I added a launch screen xib (or storyboard) and this resolved the issue on the iPhone 6 and 6 plus.

在Ryans解决方案之后,我添加了一个启动屏幕xib(或故事板),这解决了iPhone 6和6 plus上的问题。

So make sure you have it set in your project settings, it should end up looking something like this:

所以一定要在你的项目设置中设置它,它最终应该是这样的:

在iPhone 6设备和模拟器上的快照方法。

#3


0  

It seems to be a bug on Apple's side that occurs on scaled apps (those that have no design/assets/layout support for iPhone 6/6+) This one helped me get over it: snapshotViewAfterScreenUpdates glitch on iOS 8

这似乎是苹果方面的一个缺陷,它出现在缩放应用(那些没有为iPhone 6/6+提供设计/资产/布局支持的应用)上

Basically uses: [view.layer renderInContext:UIGraphicsGetCurrentContext()];

主要用途:[视图。层renderInContext:UIGraphicsGetCurrentContext()];

#1


5  

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.

到目前为止我们发现的唯一解决方案是确保应用程序为iPhone 6和6+启动图像大小,然后我们就不再有闪烁的图像了。

#2


2  

Following on from Ryans solution, I added a launch screen xib (or storyboard) and this resolved the issue on the iPhone 6 and 6 plus.

在Ryans解决方案之后,我添加了一个启动屏幕xib(或故事板),这解决了iPhone 6和6 plus上的问题。

So make sure you have it set in your project settings, it should end up looking something like this:

所以一定要在你的项目设置中设置它,它最终应该是这样的:

在iPhone 6设备和模拟器上的快照方法。

#3


0  

It seems to be a bug on Apple's side that occurs on scaled apps (those that have no design/assets/layout support for iPhone 6/6+) This one helped me get over it: snapshotViewAfterScreenUpdates glitch on iOS 8

这似乎是苹果方面的一个缺陷,它出现在缩放应用(那些没有为iPhone 6/6+提供设计/资产/布局支持的应用)上

Basically uses: [view.layer renderInContext:UIGraphicsGetCurrentContext()];

主要用途:[视图。层renderInContext:UIGraphicsGetCurrentContext()];