搜索框,导航栏随页面滑动渐变

Posted OIMM

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了搜索框,导航栏随页面滑动渐变相关的知识,希望对你有一定的参考价值。

 

 

 

简单的变化

#pragma mark - scrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat alpha = scrollView.contentOffset.y / 100;
    if (alpha >= 1) {
        alpha = 1;
    }else if (alpha <= 0)
    {
        alpha = 0;
    }
    self.naviView.backgroundColor = [UIcolor colorWithAlphaComponent:alpha];
}

 

 

 

//一些更多的变化

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if (scrollView == self.myTableView) {
        if (scrollView.contentOffset.y<(200-_homeView.mj_h)){
            float alpha = scrollView.contentOffset.y/(200-_homeView.mj_h);
            _homeView.backgroundColor = [[UIColor whiteColor]colorWithAlphaComponent:alpha];
            if (alpha>0.5) {
                if(!CGColorEqualToColor(self.titleView.backgroundColor.CGColor, [UIColor colorHexString:@"#efefef"].CGColor)){
                    [[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleDefault animated:NO];
                    self.telButton.buttonImageView.image = [UIImage imageNamed:@"sy_kf_hei_icon"];
                    self.telButton.titleLabel.textColor = [UIColor colorHexString:@"#3d3d3d"];
                    self.titleView.backgroundColor = [UIColor colorHexString:@"#efefef"];
                    self.messageLabel.textColor = [UIColor colorHexString:@"#3d3d3d"];
                    [self.messageButtonItem setImage:[UIImage imageNamed:@"zjwd_db_ssk_xx_icon"] forState:UIControlStateNormal];
                }
            }
            else{
                if(!CGColorEqualToColor(self.titleView.backgroundColor.CGColor, [UIColor whiteColor].CGColor)){
                    [[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
                    self.telButton.buttonImageView.image = [UIImage imageNamed:@"sy_kf_bai_icon"];
                    self.telButton.titleLabel.textColor = [UIColor colorHexString:@"#ffffff"];
                    self.titleView.backgroundColor = [UIColor whiteColor];
                    self.messageLabel.textColor = [UIColor colorHexString:@"#ffffff"];
                    [self.messageButtonItem setImage:[UIImage imageNamed:@"sy_xx_bai_icon"] forState:UIControlStateNormal];
                }
            }
            
        }
        else
        {
            _homeView.backgroundColor = [[UIColor whiteColor]colorWithAlphaComponent:1.0f];
            if(!CGColorEqualToColor(self.titleView.backgroundColor.CGColor, [UIColor colorHexString:@"#efefef"].CGColor)){
                [[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleDefault animated:NO];
                self.telButton.buttonImageView.image = [UIImage imageNamed:@"sy_kf_hei_icon"];
                self.telButton.titleLabel.textColor = [UIColor colorHexString:@"#3d3d3d"];
                self.titleView.backgroundColor = [UIColor colorHexString:@"#efefef"];
                self.messageLabel.textColor = [UIColor colorHexString:@"#3d3d3d"];
                [self.messageButtonItem setImage:[UIImage imageNamed:@"zjwd_db_ssk_xx_icon"] forState:UIControlStateNormal];
            }
        }
    }
}

 

以上是关于搜索框,导航栏随页面滑动渐变的主要内容,如果未能解决你的问题,请参考以下文章

iOS 超 Easy 实现 渐变导航栏

uniapp 导航栏原生标题、按钮、输入框配置

ios 导航栏透明, 上下滑动 导航栏 颜色渐变

iOS个人中心渐变动画微信对话框标签选择器自定义导航栏短信验证输入框等源码

底部应用栏在使用片段导航时向上/向下滑动(导航架构组件)

我实施滑动标签有什么问题?