它在返回横向模式后变成银色。
只有当我将其旋转为纵向,创建弹出窗口并选择导航控制器中的某些内容(推送另一个tableViewController)时才会发生这种情况。即使在viewDidLoad方法中设置属性也无效。
有人有想法吗?
它在返回横向模式后变成银色。
只有当我将其旋转为纵向,创建弹出窗口并选择导航控制器中的某些内容(推送另一个tableViewController)时才会发生这种情况。即使在viewDidLoad方法中设置属性也无效。
有人有想法吗?
viewDidLoad 方法只会在你的视图第一次显示时被调用(或者在由于内存问题而被清除时)。请尝试在您的 viewWillAppear 方法中重新设置 barStyle,甚至可以使用 splitViewController:willShowViewController:invalidatingBarButtonItem: 方法。
针对Steve(检测RootViewController的PoPView或splitView导航栏)[splitview IPAD]
你需要在RootViewController上创建一个类方法(setLand:int i),并从detailviewcontroller中调用这些方法:
- (void)splitViewController: (UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {
// LANDSCAPE !!!!
[RootViewController setLand:1];
并且
- (void)splitViewController: (UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem*)barButtonItem forPopoverController: (UIPopoverController*)pc {
// PORTRAIT!!
[RootViewController setLand:0];
在RootViewController上:
static int landscape=2;
...
// SetMethod for class variable landscape
+ (void)setLand:(int)i
{
if(landscape!=i){
landscape = i;
}
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if(landscape == 1)
{
//LANDSCAPE!
CUSTOM FOR LANDSCAPE
self.navigationController.navigationBar.barStyle =...
}
else if(landscape == 0)
{
//PORTRAIT!
CUSTOM FOR PORTRAIT
self.navigationController.navigationBar.barStyle =...
}
}
这在我的应用程序中很有效,可以编辑自定义横向/纵向navigationBar。
@Brendan G. Lim和其他遇到tintColor问题的人,我最终通过自定义导航栏解决了这个问题:
@interface CustomNavigationBar : UINavigationBar { } @end
@implementation CustomNavigationBar
-(void)setTintColor:(UIColor *)tintColor
{
[super setTintColor :[self tintColor]];
}
@end
打开MainWindow.xib,选择您想要设置颜色的导航栏。在您的Identity面板[Apple][4]中选择CustomNavigationBar作为类。
在属性面板[Apple][1]中设置栏的颜色。
就是这样!
在4.2版本中,旋转后设置navigationBar的tintColor存在问题。你可以使用上面的答案正确地设置barStyle,但无法设置tintColor。还有其他人遇到同样的问题吗?
很棒,已经解决了。
添加到我的RootViewController中,其中声明了splitviewcontroller和nav bar:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:YES];
self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
}
这个问题已经解决了,使用了以下代码
@implementation ChangeNavigationBarColor
- (void) setTintColor:(UIColor*)color
{
[super setTintColor:[[BrandingManager sharedBrandingManager] tintColorForNavigationController]];
}
@interface ChangeNavigationBarColor : UINavigationBar {
}
@end
几周前就报告了这个问题,苹果说这是4.2的已知bug。我问是否有办法修复,但至今没有回复。
用子类化/自定义导航栏替换UINavigationbar也没有用。弹出窗口似乎对UINavigationBar执行一些秘密的恶意操作,会破坏tintColor并且不允许重置它(即使在重置后,它仍然保持为“nil”)。
我基本上放弃了,并告诉客户他必须忍受它,直到下一个更新发布(希望如此)。
我也遇到了同样的问题,但在viewWillAppear中重置barStyle会导致另一个问题。在那里设置它也会在弹出窗口中显示时设置它,因此它不再与弹出窗口颜色匹配。当左侧面板在分割视图控制器中显示时,如何将barStyle设置为我想要的内容?我想我可以仅在方向为横向时在viewWillAppear中设置它,但这似乎很糟糕。此外,在splitViewController:willShowViewController:invalidatingBarButtonItem:中设置它根本不起作用,因为我认为这是在分割视图控制器将样式设置回默认值之前调用的。这似乎是苹果的一个非常愚蠢的错误。它应该将其更改回最初的样式,而不是默认样式。
你可以使用一个单独的类来更改颜色,将背景颜色设置为该类的所需颜色,然后将该类用作你的rootViewController的类。我这样做了,它有效。