为什么 setTranslucent:NO]崩溃我的应用程序?

同样的问题,但是这个问题被回避了(因为当时的NDA)并且不再活跃。

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

我把它设置在我的初始视图控制器的viewDidLoadsetTranslucent出现在自动完成,并没有抱怨,直到崩溃和谈论swizzles和事情。

任何有关这方面的信息都会很棒,我仍然有一个非常粗糙的时间在我的应用程序中获得一致的状态栏外观。

看来, translucent属性不能用UIAppearance来设定。 我不知道为什么,但我想一些属性是不支持的。 不过,我通过创build一个自定义的UIViewController来解决这个问题,并使得我的应用程序中的所有其他viewController成为该自定义viewController的一个子类。 这样,我可以设置全局属性(例如在你的情况下translucent ),将被我的应用程序中的所有其他viewControllersinheritance。 我知道这是一个很大的改变,但是我希望它有帮助。

**** 编辑 ****

从iOS 8开始,透明度可以通过UIA外观设置:

目标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 } 

你可以通过指定一个不存在的图像来欺骗它,这将使工具栏变得不透明

 [[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]; 

我不知道你的问题的答案,我从谷歌到这里,但如果你使用导航控制器,我可以改变这一行的所有半透明:

 [self.navController.navigationBar setTranslucent:NO]; 

你因为使用非法方法而崩溃。 在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属性,否则可能会抛出exception,而translucent不具有该属性。

但令我感到困惑的是,iOS8中的[[XXX appearance] method]没问题,但在iOS7中崩溃,苹果文件没有说明。

课程初始化后,您无法更改半透明属性。

 [newsViewNavigationController.navigationBar setTranslucent:NO]; 

我做了这样的事情,它的工作!