隐藏导航栏的两种方法

1.下面这种隐藏导航栏  本人在开发中使用时候发现 导航的透明设置NO  才在push页面没有黑影闪现,但是在本页面使用本隐藏导航栏的方法时候再次push 一个隐藏的导航栏 会存在黑影的闪现,由于在viewWillDisappear  调用了 [self.navigationController setNavigationBarHidden:NO animated:animated]; 同时在viewWillAppear 调用[self.navigationController setNavigationBarHidden:YES animated:animated];  很短时间内连续调用这个两个方法导致。

所以注意使用时的控制  。

- (void)viewWillAppear:(BOOL)animated{

    [super  viewWillAppear:animated];

    [self.navigationController  setNavigationBarHidden:YES animated:animated];

}

- (void)viewWillDisappear:(BOOL)animated{

   [super  viewWillDisappear:animated];

   [self.navigationController  setNavigationBarHidden:NO  animated:animated];

}


2.后来本人使用 透明化导航栏 但是这里不会真正隐藏导航栏只是导航栏透明了而已,同时去除黑线,如果不是使用[self imageWithColor:[UIColor clearColor]  而使用[[UIImage  alloc]init] 那只是去除黑线

- (void)viewWillAppear:(BOOL)animated{

      [super  viewWillAppear:animated];

      [self.navigationController.navigationBar  setBackgroundImage:[self imageWithColor:[UIColor clearColor]  forBarMetrics:UIBarMetricsDefault];

      [self.navigationController.navigationBar setShadowImage:[self  imageWithColor:[UIColor  clearColor]]];

}

- (void)viewWillDisappear:(BOOL)animated{

        [super   viewWillDisappear:animated]; 

        [self.navigationController.navigationBar   setBackgroundImage:nil      forBarMetrics:UIBarMetricsDefault];

        [self.navigationController.navigationBar   setShadowImage:nil];

}

- (UIImage*)imageWithColor:(UIColor*)color

{

   CGRect rect =CGRectMake(0.0f,0.0f,1.0f,1.0f);

   UIGraphicsBeginImageContext(rect.size);

   CGContextRef context =UIGraphicsGetCurrentContext();

   CGContextSetFillColorWithColor(context, [colorCGColor]);

   CGContextFillRect(context, rect);

   UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

  UIGraphicsEndImageContext();

  return image;

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容