application life cycle issue

2019-09-21 19:31发布

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;  
}

after maximize it goes to applicationDidBecomeActive thats why i put above code in applicationDidBecomeActive but its not working, why this is happening?
before minimize
enter image description here
after minimize & maximize again it looks like below i.e. height again automatically sets to 44.
enter image description here

Update: i written following code in 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" );

   }

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.

2条回答
贪生不怕死
2楼-- · 2019-09-21 20:07

When your app opens from the background application:didFinishLaunchingWithOptions: does not get called. You want to use either applicationWillEnterForeground: or applicationDidBecomeActive: instead. Check out the UIApplicationDelegate protocol reference for more information.


EDIT: In response to the question author's edits, I will say this. I played around with this code in an app of mine, and I've been able to reproduce the problem. I've tried a number of solutions to fix it, including resetting the frame of the navbar in a UINavigationController's layoutSubviews. I suggest creating a sample project that reproduces this issue and submitting it to Apple's Bug reporter, or creating a UINavigationBar subclass that repositions and resizes itself.

查看更多
再贱就再见
3楼-- · 2019-09-21 20:24

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

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

查看更多
登录 后发表回答