iOS导航栏随滑动渐隐渐现且不影响push页面导航栏的实现方式

来源:互联网 发布:淘宝老客户维护方案 编辑:程序博客网 时间:2024/05/16 16:23
//自定义导航栏视图
@property(nonatomic,strong)UIView * naviView;

viewDidLoad中:
if([selfrespondsToSelector:@selector(setEdgesForExtendedLayout:)])
    {
        [
selfsetEdgesForExtendedLayout:UIRectEdgeNone];
    }

self.naviView= [[UIViewalloc]initWithFrame:CGRectMake(0,0,YJScreenWidth,64)];
   
self.naviView.backgroundColor= THEME_Color;
    [
self.viewaddSubview:self.naviView];
    [self.viewbringSubviewToFront:self.naviView];

- (void)viewWillAppear:(BOOL)animated
{
    [
superviewWillAppear:animated];
    [
self.navigationControllersetNavigationBarHidden:YESanimated:animated];
}

- (
void)viewWillDisappear:(BOOL)animated
{
    [
superviewWillDisappear:animated];
    [
self.navigationControllersetNavigationBarHidden:NOanimated:animated];
}

#pragma mark - scrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView*)scrollView
{
   
CGFloat alpha = scrollView.contentOffset.y/ 100;
   
if (alpha >=1) {
        alpha =
1;
    }
elseif (alpha <=0)
    {
        alpha =
0;
    }
   
self.naviView.backgroundColor= [THEME_ColorcolorWithAlphaComponent:alpha];
}
0 0
原创粉丝点击