在使用系统自带的NavigationBar时 在设置 透明和背景色时 不是很自由,而且最为严重的问题是 将
self.navigationController.navigationBar.translucent = YES,或者 self.navigationController.navigationBar.translucent = NO时
控制器的frame会有64个像素的差值,很不好处理。同时也会有很多别的问题,如下的问题:
使用edgesForExtendedLayout = UIRectEdgeNone;后,导航栏想设置为透明,却变黑色
复制代码
|
这时如果使用edgesForExtendedLayout = UIRectEdgeNone;导航栏就会变成黑色.
如果去掉edgesForExtendedLayout = UIRectEdgeNone; 这句话, 就会透明正常... 但这时,view就会顶到最上面,也就不是从导航栏下面开始view。
如何让navigationBar透明的同时上面的navigationItem不透明
解决办法: 这样就行了 以后没有那么多的麻烦了。 设置navigationBar的背景或透明或隐藏就不会改变Viewcontroller的Fram了!。
#import "UDNavigationController.h"
@implementation UDNavigationController
@synthesize alphaView;
-(id)initWithRootViewController:(UIViewController *)rootViewController{
self = [super initWithRootViewController:rootViewController];
if (self) {
CGRect frame = self.navigationBar.frame;
alphaView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height+20)];
alphaView.backgroundColor = [UIColor blueColor];
[self.view insertSubview:alphaView belowSubview:self.navigationBar];
// [self.navigationBar setBackgroundImage:[UIImage imageNamed:@"bigShadow.png"] forBarMetrics:UIBarMetricsCompact];
[self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsCompact];
self.navigationBar.layer.masksToBounds = YES;
// self.navigationBar.translucent
// NSLog(@"the translucent is %", self.navigationBar.translucent );
NSLog(@"the translucent is: %@" ,self.navigationBar.translucent ? @"YES" : @"NO");
}
return self;
}
-(void)setAlph{
if (_changing == NO) {
_changing = YES;
if (alphaView.alpha == 0.0 ) {
[UIView animateWithDuration:0.5 animations:^{
alphaView.alpha = 1.0;
} completion:^(BOOL finished) {
_changing = NO;
}];
}else{
[UIView animateWithDuration:0.5 animations:^{
alphaView.alpha = 0.0;
} completion:^(BOOL finished) {
_changing = NO;
}];
}
}
}
-(void)setBackGroundImage{
// alphaView.backgroundColor = [UIColor yellowColor];
alphaView.image = [UIImage imageNamed:@"zapya_navgation_bar_img.png"];
}
@end