2013-10-01 60 views
37

同樣的問題this,但問題是(當時因爲NDA)的迴避,不再活躍。爲什麼[[UINavigationBar appearance] setTranslucent:NO]會導致我的應用程序崩潰?

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** Illegal property type, c for appearance setter, _installAppearanceSwizzlesForSetter:' 

我在我的初始視圖控制器的設置viewDidLoadsetTranslucent出現在自動完成,並沒有抱怨,直到崩潰和討論swizzles和事情。

在這個任何信息將是巨大的,我仍然有一個非常粗略的時間去在我的應用程序一致的狀態欄的外觀。

+1

你在iOS的7模擬器或在iOS 7設備上運行?如果沒有,'setTranslucent'屬性將不存在,從而導致崩潰。 – hgwhittle

+0

它在模擬器或設備上崩潰? – user

+0

你說它崩潰了嗎?我不太瞭解你的迴應。 – hgwhittle

回答

53

看來,translucent財產就不能使用UIAppearance設置。我不知道爲什麼,但我想一些屬性不支持。但是,我通過創建自定義UIViewController並將我應用中的所有其他viewController作爲該自定義viewController的子類來解決此問題。這樣,我可以設置全局屬性(例如您的案例中的translucent),該屬性將被我的應用程序中的所有其他viewController繼承。我知道這是一個很大的改變,但我希望它有幫助。

**** EDIT ****

作爲iOS 8的的,半透明性可與UIAppearance設置:

目標C

if([UIDevice currentDevice].systemVersion.floatValue >= 8.0) { 

    [[UINavigationBar appearance] setTranslucent:YES]; 
} 

夫特

if (UIDevice.currentDevice().systemVersion as NSString).floatValue >= 8.0 { 

    UINavigationBar.appearance().translucent = true 
} 
+3

我最終只是手動設置每個視圖控制器中的半透明度。更快,但不像子類或定義協議那麼幹淨。 – user

+5

iOS 8開始通過UIAppearance支持設置半透明。 – Pwner

+1

儘管解釋有意義,但對於iOS 7,conformsToProtocol檢查也已通過。在設置半透明屬性之前,系統版本檢查結束。 –

8

你可以通過指定一個不存在的ima來欺騙它GE,這將amke工具欄去不透明

[[UIToolbar appearance] setBackgroundColor:[UIColor colorWithRed:219.0/255.0 green:67.0/255.0 blue:67.0/255.0 alpha:1.0]]; 

[[UIToolbar appearance] setBackgroundImage:[[UIImage alloc] init] forToolbarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault]; 
2

我不知道回答你的問題,我從谷歌來到這裏,但如果您使用的導航控制器,我可以改變所有的半透明這一行:

[self.navController.navigationBar setTranslucent:NO]; 
0

在類初始化後,您無法更改半透明屬性。

[newsViewNavigationController.navigationBar setTranslucent:NO]; 

我做了這樣的事情,它的工作!

2

你崩潰,因爲你使用非法方法。 在UIAppearance,它說

To participate in the appearance proxy API, tag your appearance property selectors in your header with UI_APPEARANCE_SELECTOR. 

這意味着當你使用[[XXX appearance] method],該方法方法必須具有屬性UI_APPEARANCE_SELECTOR,或者它可能會拋出異常,並且translucent沒有它。

但令我百思不解的是,在[[XXX appearance] method]它iOS8上的確定,但在iOS7和蘋果文檔崩潰不說了吧。

相關問題