navigationController alpha会重置吗?当应用程序从后台激活时

时间:2013-12-20 08:33:49

标签: ios ios7 navigation reload navigationcontroller

  1. 我在AUIController中,navigationController.navigationBar.alpha == 0.500
  2. 我按了主页按钮。
  3. 我点击appIcon返回AUIController。 navigationController.navigationBar.alpha为1.000
  4. 如何保持navigationController.navigationBar的alpha = 0.5000;

    我试过..

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

    但是当应用程序变为活动状态时,alpha 0.50变为1.00 willShowViewController不能被调用

3 个答案:

答案 0 :(得分:2)

您可以使用KVO来做到这一点。在viewDidLoad的{​​{1}}中添加此代码AUIController

并实现此功能:

[self.navigationController.navigationBar addObserver:self forKeyPath:@"alpha" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:(__bridge void *)(self)];

答案 1 :(得分:0)

只需在方法

中记下以下代码即可

AppDelegate.m文件。

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

我希望这会对你有所帮助。

答案 2 :(得分: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;

}