如何保持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不能被调用
答案 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;
}