NavigationBar 渐隐效果


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

    CGFloat alpha=scrollView.contentOffset.y/90.0f>1.0f?1:scrollView.contentOffset.y/90.0f;

     [self.navigationController.navigationBar setBackgroundImage:[self getImageWithAlpha:alpha] forBarMetrics:UIBarMetricsDefault];

    }

#pragma handle image -mark

//合成图片

-(UIImage *)getImageWithAlpha:(CGFloat)alpha{

    

    UIColor *color=[UIColor colorWithRed:1 green:0 blue:0 alpha:alpha];

    CGSize colorSize=CGSizeMake(1, 1);

    UIGraphicsBeginImageContext(colorSize);

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetFillColorWithColor(context, color.CGColor);

    CGContextFillRect(context, CGRectMake(0, 0, 1, 1));

    

    UIImage *img=UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return img;

}


你可能感兴趣的:(NavigationBar 渐隐效果)