2017-07-28 40 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