我是靠谱客的博主 尊敬魔镜,最近开发中收集的这篇文章主要介绍导航栏和页面融合的渐变色,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView == self.mainTableView) {//滚动距离判定
        if (scrollView.contentOffset.y > 135) {
            self.title = @"书籍详情";
            [self changeStatusBarColorToDark:NO];
            self.shareButton.selected = YES;
            [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@""]
                                                          forBarMetrics:UIBarMetricsDefault];
        }else {
            self.title = @"";
            self.shareButton.selected = NO;
            [self changeStatusBarColorToDark:YES];
            [self.navigationController.navigationBar setBackgroundImage:self.statusBarImage
                                                          forBarMetrics:UIBarMetricsDefault];
        }

        if (scrollView.contentOffset.y > 0 && scrollView.contentOffset.y < 135) {
            self.backgroundImg.frame = CGRectMake(0, -scrollView.contentOffset.y, SWIDTH, 135);
        }
    }
}

- (void)changeStatusBarColorToDark:(BOOL)dark {
    [[NSNotificationCenter defaultCenter] postNotificationName:kChangeStatusBarColorNotificatonName
                                                        object:nil
                                                      userInfo:@{@"dark":@(dark)}];
}

//导航栏图片
- (void)statusBarSetImage:(UIImage *)img {
    UIImage *orgImage = [img applyBlurWithRadius:25 tintColor:[UIColor colorWithWhite:1 alpha:0.6] saturationDeltaFactor:1.8 maskImage:nil];
    UIImage *clipImg = [orgImage clipWithImageRect:CGRectMake(100, 0, SWIDTH, 64)];
    clipImg = [clipImg resizableImageWithCapInsets:UIEdgeInsetsZero resizingMode:UIImageResizingModeStretch];
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.navigationController.navigationBar setBackgroundImage:clipImg
                                                      forBarMetrics:UIBarMetricsDefault];
        self.backgroundImg.image = [orgImage clipWithImageRect:CGRectMake(100, 64, SWIDTH, 135)];


    });
    self.statusBarImage = clipImg;
}

//渐变layer
- (void)insertTransparentGradient {
    UIColor *colorOne = [UIColor colorWithWhite:1.0 alpha:0.0];
    UIColor *colormid = [UIColor colorWithWhite:1.0 alpha:0.1];
    UIColor *colorTwo = [UIColor colorWithWhite:1.0 alpha:1.0];
    NSArray *colors = [NSArray arrayWithObjects:(id)colorOne.CGColor,colormid.CGColor, colorTwo.CGColor, nil];
    NSNumber *stopOne = [NSNumber numberWithFloat:0.0];
    NSNumber *stopMid = [NSNumber numberWithFloat:0.3];
    NSNumber *stopTwo = [NSNumber numberWithFloat:1.0];
    NSArray *locations = [NSArray arrayWithObjects:stopOne, stopMid, stopTwo, nil];

    //crate gradient layer
    CAGradientLayer *headerLayer = [CAGradientLayer layer];

    headerLayer.colors = colors;
    headerLayer.locations = locations;
    headerLayer.frame = self.backgroundImg.bounds;
    [self.backgroundImg.layer insertSublayer:headerLayer atIndex:0];
}

最后

以上就是尊敬魔镜为你收集整理的导航栏和页面融合的渐变色的全部内容,希望文章能够帮你解决导航栏和页面融合的渐变色所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(33)

评论列表共有 0 条评论

立即
投稿
返回
顶部