0
点赞
收藏
分享

微信扫一扫

详解 iOS navigationBar 的设置问题 详解2 关于隐藏和透明问题


在使用系统自带的NavigationBar时 在设置 透明和背景色时 不是很自由,而且最为严重的问题是 将

self.navigationController.navigationBar.translucent = YES,或者  self.navigationController.navigationBar.translucent = NO时 

控制器的frame会有64个像素的差值,很不好处理。同时也会有很多别的问题,如下的问题:

使用edgesForExtendedLayout = UIRectEdgeNone;后,导航栏想设置为透明,却变黑色   





设置导航栏背景为透明的代码:


复制代码 


1.  [self.navigationController.navigationBar setBackgroundImage:[UIImage new]
2.                                                forBarMetrics:UIBarMetricsDefault];
3. 
4.  self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
5.  self.navigationController.navigationBar.shadowImage = [UIImage new];


这时如果使用edgesForExtendedLayout = UIRectEdgeNone;导航栏就会变成黑色.


如果去掉edgesForExtendedLayout = UIRectEdgeNone; 这句话, 就会透明正常... 但这时,view就会顶到最上面,也就不是从导航栏下面开始view。



如何让navigationBar透明的同时上面的navigationItem不透明   





#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





举报

相关推荐

0 条评论