is there something wrong of iOS simulator's 'color offscreen-rendered' function?

Viewed 1061

i want to see which view is offscreen-rendered in my app.So i use the iOS simulator's 'color offscreen-rendered' function,it can color those offscreen-rendered view by yellow color.But after the app launched,the whole screen is colored by yellow and i don't believe it.

Then i try my test code like:

- (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];
}

As you can see above,i simply set the window's rootViewController three times different by orginal controllers: 'UITabBarController','UINavigationController' and 'UIViewController'.

Guess what?

Only the 'UIViewController' is not whole screen colored!!!

enter image description here

So anyOne knows why the orginal rootViewController and UINavigationController will occur the whole screen offscreen-render??????

1 Answers

It's because default translucent value of UITabBar and UINavigationBar are YES.

You should check Apple documents for UINavigationBar.translucent and UITabBar.translucent for more information.

A small demo by creating a UINavigationController with a red background root view controller, we can compare the difference when translucent is YES and NO.

- (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;
}

By default, translucent is YES. So you can see background of UINavigationBar has a little red.

enter image description here

Color offscreen-rendered

enter image description here

But when we set translucent to NO. No more red in background of UINavigationBar.

enter image description here

Color offscreen-rendered

enter image description here


We have transparent here so that's why screen is colored. You can try similar thing with translucent of UITabBar.

To avoid offscreen-rendered with UINavigationController and UITabBarController, you should set this property to NO.

Related