Question

  1. I was in the AUIController ,the navigationController.navigationBar.alpha == 0.500
  2. I pressed the home button .
  3. I clicked the appIcon get Back to AUIController. the navigationController.navigationBar.alpha to 1.000

how can I do to keep the navigationController.navigationBar's alpha = 0.5000 ;

I had try ..

AUIController : UIViewController  <...,UINavigationControllerDelegate>

- (void) navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {

    if (viewController == self) {
            //NSLog(@"self");
        //self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.000 green:0.000 blue:0.000 alpha:1.000];
            self.navigationController.navigationBar.alpha = 0.500;
            self.navigationController.navigationBar.translucent = YES;
        } else {
            self.navigationController.navigationBar.alpha = 1.000;
            self.navigationController.navigationBar.translucent = NO;
        }
    }

But when the app become active ,the alpha 0.50 become 1.00 willShowViewController not be called

Was it helpful?

Solution

You can use KVO to do that. In viewDidLoad of AUIController add this code [self.navigationController.navigationBar addObserver:self forKeyPath:@"alpha" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:(__bridge void *)(self)];

and implement this function:

-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    NSLog([change description]);
    UIViewController *viewController = (__bridge UIViewController*)context;
    if ([viewController isKindOfClass:[AUIViewController class]]) {
        if (self.navigationController.navigationBar.alpha == 1) {
            self.navigationController.navigationBar.alpha = 0.500;
            self.navigationController.navigationBar.translucent = YES;
        }
    }
}

OTHER TIPS

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    self.navigationBar.translucent = NO;
    [self.navigationController.layer removeFromSuperlayer];
}

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    self.navigationBar.translucent = YES;

}

just write down the following code in method

AppDelegate.m file.

- (void)applicationWillEnterForeground:(UIApplication *)application
 { 

    int count=self.navigationController.viewControllers.count;

    if([[[self.navigationController viewControllers] objectAtIndex:count-1] isKindOfClass:[AUIController Class]])
    {
        self.navigationController.navigationBar.alpha = 0.500;
        self.navigationController.navigationBar.translucent = YES;
    }
   else
    {
      self.navigationController.navigationBar.alpha = 1.000;
      self.navigationController.navigationBar.translucent = NO;
    }
}

i hope this will help you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top