Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
369 views
in Technique[技术] by (71.8m points)

iphone - application life cycle issue

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...