0
  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

Melih Büyükbayram
  • 3,100
  • 2
  • 17
  • 16
xddxz.xu
  • 3
  • 3

3 Answers3

2

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;
        }
    }
}
sahara108
  • 2,829
  • 1
  • 22
  • 41
0

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.

guptha
  • 529
  • 1
  • 4
  • 9
hpp
  • 619
  • 3
  • 13
  • it will set ok, But after setting the alpha (about 1 second) ,the navigationController.navigationBar will be reset to 1.000 thank u – xddxz.xu Dec 20 '13 at 09:13
0
- (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;

}
Melih Büyükbayram
  • 3,100
  • 2
  • 17
  • 16