【问题标题】:Snapshot methods broken on iPhone 6 device and simulatoriPhone 6 设备和模拟器上的快照方法损坏
【发布时间】:2014-11-15 01:45:21
【问题描述】:

由于某些未知原因,iPhone 6 模拟器(和设备)上的所有屏幕截图方法似乎都可能存在错误。每当我调用任何截图方法时,包括:

snapshotViewAfterScreenUpdates: resizableSnapshotViewFromRect: drawViewHierarchyInRect:

将 afterScreenUpdates 设置为 YES,屏幕会闪烁。如果设置为 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;
}

任何帮助将不胜感激!

【问题讨论】:

    标签: ios objective-c ios8 iphone-6


    【解决方案1】:

    我们在运行以下代码时遇到了同样的问题:

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

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

    【讨论】:

      【解决方案2】:

      继 Ryans 解决方案之后,我添加了一个启动屏幕 xib(或情节提要),这解决了 iPhone 6 和 6 plus 上的问题。

      因此,请确保您在项目设置中进行了设置,它最终应该看起来像这样:

      【讨论】:

        【解决方案3】:

        这似乎是 Apple 方面的一个错误,发生在缩放的应用程序(那些不支持 iPhone 6/6+ 的设计/资产/布局的应用程序) 这个帮助我克服了它: snapshotViewAfterScreenUpdates glitch on iOS 8

        基本用途: [view.layer renderInContext:UIGraphicsGetCurrentContext()];

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2010-09-27
          • 2017-03-12
          • 1970-01-01
          • 2011-05-08
          • 2012-10-26
          相关资源
          最近更新 更多