应用生命周期问题

我已经做了导航栏的变化意味着我已经增加了导航栏的高度,并作出了一些自定义的变化,它工作正常,但是当我最小化应用程序,并再次最大化,它只显示原始高度是我做了什么变化,那些不最小化后工作,我的代码是

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSLog(@" im in didFinishLaunchingWithOptions" ); [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"TopHeader"] forBarMetrics:UIBarMetricsDefault]; [[UINavigationBar appearance] setFrame:CGRectMake(0, 0, 320, 55)]; [[UINavigationBar appearance] setTitleVerticalPositionAdjustment:(-15.0) forBarMetrics:UIBarMetricsDefault]; [[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys: [UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0], UITextAttributeTextColor, [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8],UITextAttributeTextShadowColor, [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset, [UIFont fontWithName:@"HelveticaNeue-CondensedBlack" size:16.0], UITextAttributeFont, nil]]; return YES; } 

之后最大化到applicationDidBecomeActive这就是为什么我把上面的代码在applicationDidBecomeActive但它不工作,为什么发生这种情况?
最小化之前
在这里输入图像说明
经过最小化和最大化后,它看起来像下面,即高度自动设置为44。
在这里输入图像说明

更新:我写了下面的代码在applicationWillEnterForeground

 - (void)applicationWillEnterForeground:(UIApplication *)application { UINavigationController *my=(UINavigationController * )self.window.rootViewController; UINavigationBar *navigationBar = [my navigationBar]; CGRect frame = [navigationBar frame]; frame.size.height = 55.0f; [navigationBar setFrame:frame]; NSLog(@" im in applicationWillEnterForeground" ); } 

在debugging的时候,当我写它的描述时,它显示的高度是55.但在屏幕上,它仍然看起来像第二个图像。 为什么会这样呢?

当您的应用程序从后台application:didFinishLaunchingWithOptions:程序打开时application:didFinishLaunchingWithOptions:不会被调用。 您想要使用applicationWillEnterForeground:applicationDidBecomeActive:来代替。 查看UIApplicationDelegate 协议参考了解更多信息。


编辑:在回应作者的编辑问题,我会说这个。 我在我的一个应用程序中使用了这个代码,我已经能够重现这个问题。 我已经尝试了很多解决scheme来修复它,包括在UINavigationControllerlayoutSubviews重置导航栏的框架。 我build议创build一个重现此问题并将其提交给Apple的Bug记者的示例项目,或者创build一个重新定位和调整自身大小的UINavigationBar子类。

我解决了这个问题,只是覆盖了UINavigationBar&在LayoutSubViews中设置navigationBar的高度。

 @implementation UINavigationBar (customNAvigBar) - (void)layoutSubviews { [self setFrame:CGRectMake(0, 0, 320, 55)]; } @end 

这意味着每当我绘制自动调用导航栏并设置高度。