gpt4 book ai didi

ios - iOS模拟器的 'color offscreen-rendered'功能有问题吗?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:11:38 25 4
gpt4 key购买 nike

我想看看我的应用程序中哪个 View 是离屏渲染的。所以我使用 iOS 模拟器的“颜色离屏渲染”功能,它可以用黄色为那些离屏渲染的 View 着色。但是在应用程序启动后,整个屏幕都是黄色的,我不相信。

然后我尝试我的测试代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];

self.window.rootViewController = [[UITabBarController alloc] init];
// self.window.rootViewController = [[UINavigationController alloc] init];
// self.window.rootViewController = [[UIViewController alloc] init];

[self.window makeKeyWindow];
}

正如您在上面看到的,我只是将窗口的 rootViewController 设置为原始 Controller 的三倍不同:“UITabBarController”、“UINavigationController”和“UIViewController”。

你猜怎么着?

只有“UIViewController”不是全屏彩色!!!

enter image description here

所以有人知道为什么原来的rootViewController和UINavigationController会出现整屏离屏渲染吗?????

最佳答案

因为UITabBarUINavigationBar的默认translucent值为YES

您应该查看 Apple 文档中的 UINavigationBar.translucentUITabBar.translucent获取更多信息。

通过创建一个带有红色背景 Root View Controller 的 UINavigationController 的小演示,我们可以比较 translucentYES

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];

UIViewController* viewController = [[UIViewController alloc] init];
viewController.view.backgroundColor = [UIColor redColor];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController];
// nav.navigationBar.translucent = NO;
self.window.rootViewController = nav;

[self.window makeKeyWindow];
return YES;
}

默认情况下,半透明为 YES。所以你可以看到 UINavigationBar 的背景有一点红色。

enter image description here

颜色离屏渲染

enter image description here

但是当我们把translucent设置为NO的时候UINavigationBar 的背景不再是红色。

enter image description here

颜色离屏渲染

enter image description here


我们这里是透明的,所以屏幕是彩色的。您可以使用 UITabBartranslucent 尝试类似的事情。

要避免使用 UINavigationControllerUITabBarController 进行离屏渲染,您应该将此属性设置为 NO

关于ios - iOS模拟器的 'color offscreen-rendered'功能有问题吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45368350/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com