应用程序生命周期问题 [英] application life cycle issue

查看:106
本文介绍了应用程序生命周期问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经更改了导航栏,这意味着我增加了导航栏的高度&进行了一些自定义更改,效果很好,但是当我最小化应用程序并再次最大化它时,它仅显示原始高度,这是我所做的更改,最小化后这些无效,我的代码是

i have made changes in navigation bar means i have increasd the height of navigation bar & made some custom changes,it works fine but when i minimizes the application and again maximize it, it shows only original height that is what changes i made, those not works after minimization, my code is

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    NSLog(@" i m 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.

after maximize it goes to applicationDidBecomeActive thats why i put above code in applicationDidBecomeActive but its not working, why this is happening?
before minimize

after minimize & maximize again it looks like below i.e. height again automatically sets to 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(@" i m in applicationWillEnterForeground" );

   }

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

at the time of debugging when i writes its description it shows that height is 55. but on screen it still looks like second image. why this is happening.

推荐答案

我解决了这个问题,只是覆盖了UINavigationBar&在LayoutSubViews中设置导航栏的高度.

I solved this problem, just overrides the UINavigationBar & in LayoutSubViews set the height of navigationBar.

@implementation UINavigationBar (customNAvigBar)

- (void)layoutSubviews
{
    [self setFrame:CGRectMake(0, 0, 320, 55)];
}

@end

这意味着每当我绘制navigationBar时,它都会自动调用&设置高度.

that means whenever i draws the navigationBar it calls automatically & sets the height.

这篇关于应用程序生命周期问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆