码迷,mamicode.com
首页 > 其他好文 > 详细

UITableView 头部图片 图片拉伸

时间:2016-05-22 13:45:07      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

UITableView上面添加一个大图片,拖动tableView,图片拉伸,停止拖动,图片变为原来尺寸

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

{

    CGFloat offsetY = scrollView.contentOffset.y;

    CGFloat offsetH = imageBGHeight + offsetY;

    if (offsetH < 0) {

        CGRect frame = self.imageBG.frame;

        frame.size.height = imageBGHeight - offsetH;

        frame.origin.y = -imageBGHeight + offsetH;

        self.imageBG.frame = frame;

    }

 

// 此处是设置导航栏颜色的变化的    

    CGFloat alpha = offsetH / imageBGHeight;

    [self.navigationController.navigationBar setBackgroundImage:[self imageWithColor:[[UIColor cyanColor] colorWithAlphaComponent:alpha]] forBarMetrics:UIBarMetricsDefault];

}

#pragma mark - 返回一张纯色图片

/** 返回一张纯色图片 */

- (UIImage *)imageWithColor:(UIColor *)color {

    // 描述矩形

    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);

    // 开启位图上下文

    UIGraphicsBeginImageContext(rect.size);

    // 获取位图上下文

    CGContextRef context = UIGraphicsGetCurrentContext();

    // 使用color演示填充上下文

    CGContextSetFillColorWithColor(context, [color CGColor]);

    // 渲染上下文

    CGContextFillRect(context, rect);

    // 从上下文中获取图片

    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();

    // 结束上下文

    UIGraphicsEndImageContext();

    return theImage;

}

UITableView 头部图片 图片拉伸

标签:

原文地址:http://www.cnblogs.com/fantasy3588/p/5516572.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!