导航栏上拉渐变,,头视图下拉放大




 /// 状态栏变色  info.plist 添加 View controller-based status bar appearance  为 NO

- (UIStatusBarStyle)preferredStatusBarStyle{

    if (self.changeColor == YES) {

        return UIStatusBarStyleLightContent;

    }else{

        return UIStatusBarStyleDefault;

    }

}


1.

-(void)viewWillAppear:(BOOL)animated{

    [super viewWillAppear:animated];

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

}

-(void)viewWillDisappear:(BOOL)animated{

    [super viewWillAppear:animated];

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

}


2.

- (void)viewDidLoad {

    [super viewDidLoad];

    // 导航条

    self.headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, Width, nanH)];

    self.headView.alpha = 0;

    self.headView.backgroundColor = [UIColor whiteColor];

    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, nanH - 0.7, Width, 0.7)];

    [self.headView addSubview:line];

    line.backgroundColor = [UIColor lightGrayColor];

    [self.view addSubview:self.headView];

    ///

    self.backImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"返回-7"]];

    self.backImage.frame = CGRectMake(18, statusH+12, 20, 20);

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backAction)];

    self.backImage.userInteractionEnabled = YES;

    [self.backImage addGestureRecognizer:tap];

    [self.view addSubview:self.backImage];

    ///

    self.backButton = [UIButton buttonWithType:UIButtonTypeSystem];

 [self.backButton setTitle:NSLocalizedString(@"Back", nil) forState:UIControlStateNormal];

    [self.view addSubview:self.backButton];

    self.backButton.tintColor = [UIColor whiteColor];

    self.backButton.frame = CGRectMake(35, statusH+12, 40, 20);

    [self.backButton addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];

    //

    self.titlLabel = [[UILabel alloc] initWithFrame:CGRectMake(Width/2-100, statusH+12, 200, 20)];

    self.titlLabel.text = NSLocalizedString(@"Personal circle", nil);

    [self.view addSubview:self.titlLabel];

    self.titlLabel.textAlignment = NSTextAlignmentCenter;

    self.titlLabel.textColor = [UIColor whiteColor];

    //// 刷新状态栏的颜色

    self.changeColor = YES;

    [self setNeedsStatusBarAppearanceUpdate];

    /// 创建tableview  添加头视图

}


3.


- (void)scrollViewDidScroll:(UIScrollView *)scrollView{

CGFloat scroll=scrollView.contentOffset.y;

    CGFloat imageH = 209;///209头视图高度

    /// 导航栏View渐变

    if (scroll > 0) {

        self.headView.alpha = 1 * (scroll / (imageH-64));

    }else{

        self.headView.alpha = 0;

    }

    /// 导航栏返回按钮标题变色

    if (scroll>=(imageH-64-49)) {

        self.backImage.image = [UIImage imageNamed:@"返回-4"];

        self.backButton.tintColor = [UIColor blackColor];

        self.titlLabel.textColor = [UIColor blackColor];

        //// 刷新状态栏的颜色

        self.changeColor = NO;

        [self setNeedsStatusBarAppearanceUpdate];

    }else{

        self.backImage.image = [UIImage imageNamed:@"返回-7"];

        self.backButton.tintColor = [UIColor whiteColor];

        self.titlLabel.textColor = [UIColor whiteColor];

        //// 刷新状态栏的颜色

        self.changeColor = YES;

        [self setNeedsStatusBarAppearanceUpdate];

    }

    /// 头图缩放

    if (scroll<0) {

        self.headerView.backImageView.frame = CGRectMake(scroll*Width/imageH/2, scroll, Width+2*fabs(scroll*Width/imageH), imageH+fabs(scroll));

    }else{

        self.headerView.backImageView.frame = CGRectMake(0, 0, Width, imageH);

    }

}


阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页