在 iPad (iOS 8) 上运行 iPhone 应用程序,使用 drawViewHierarchyInRect 拍摄快照并在两个 View Controller 之间制作自定义动画。这一切在 iPhone 上运行良好,但当该应用程序在 iPad 上(不是通用应用程序,仅限 iPhone)时,您可以在动画开始时看到一个错误快照的简短一瞥。基本上它似乎拍摄了整个 iPad 屏幕的快照,包括黑色边缘,而不仅仅是模拟的 iPhone 屏幕。该应用程序还隐藏了状态栏,但您可以在简短的一瞥中看到状态栏,这意味着它可能是 iOS 中的某种错误,因为 iPad 始终在屏幕顶部显示 iPhone 应用程序的状态栏。
这是截图代码;
UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 0.0);
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:update];
UIImage *snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
顺便说一句,当使用 Airplay 在 Apple TV 上显示应用程序时,也会发生闪烁。
最佳答案
用下面的代码替换你的代码,
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, 0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *im = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
关于ios - iPad 上的 iPhone 应用程序 : drawViewHierarchyInRect causes glitch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30119827/