【问题标题】:is there something wrong of iOS simulator's 'color offscreen-rendered' function?iOS模拟器的'color offscreen-rendered'功能有问题吗?
【发布时间】:2017-07-28 08:18:31
【问题描述】:

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

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

- (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 设置为原始控制器的三倍:'UITabBarController'、'UINavigationController' 和 'UIViewController'。

你猜怎么着?

只有 'UIViewController' 不是全屏彩色!!!

所以任何人都知道为什么原来的rootViewController和UINavigationController会出现全屏offscreen-render??????

【问题讨论】:

    标签: ios render simulator


    【解决方案1】:

    这是因为UITabBarUINavigationBar的默认translucent值是YES

    您应该查看 Apple 文档中的 UINavigationBar.translucentUITabBar.translucent 以了解更多信息。

    通过创建UINavigationController 与红色背景根视图控制器的小演示,我们可以比较translucentYESNO 时的区别。

    - (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的背景有点红。

    屏幕外渲染的颜色

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

    屏幕外渲染的颜色


    我们这里是透明的,这就是为什么屏幕是彩色的。您可以使用translucentUITabBar 尝试类似的事情。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-24
      • 1970-01-01
      • 2011-11-23
      • 2014-06-05
      相关资源
      最近更新 更多