美文网首页
隐藏导航栏的两种方法

隐藏导航栏的两种方法

作者: zeqinjie | 来源:发表于2016-02-22 16:17 被阅读256次

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;

}

相关文章

网友评论

      本文标题:隐藏导航栏的两种方法

      本文链接:https://www.haomeiwen.com/subject/lcjbkttx.html