2017-07-28 33 views
2

我想看看哪些视图在屏幕上呈现在我的应用程序中。因此,我使用iOS模拟器的“屏幕外渲染”功能,它可以通过黄颜色给那些离屏渲染的视图着色。但是,在应用程序启动后,整个屏幕被黄色着色,我不相信它。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'不是全屏色!

enter image description here

所以任何人都知道为什么原单RootViewController的和的UINavigationController将出现整个屏幕屏幕外渲染??????

回答

1

这是因为默认translucentUITabBarUINavigationBarYES

有关更多信息,您应该检查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的背景有点红。

enter image description here

彩色屏幕外渲染

enter image description here

但是,当我们设置半透明NO。在UINavigationBar的背景中不再有红色。

enter image description here

彩色屏幕外渲染

enter image description here


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

要避免使用UINavigationControllerUITabBarController的屏幕外渲染,应将此属性设置为NO