zoukankan      html  css  js  c++  java
  • UITableView 头部图片 图片拉伸

    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;

    }

    第二种方法  

    - (void)scrollViewDidScroll:(UIScrollView *)scrollView

    {

        CGFloat offsetY  = scrollView.contentOffset.y;

        if (offsetY < -KActivityDetailHeadH) {

            CGRect frame = _expandZoomImageView.frame;

            frame.origin.y = offsetY - 20;

            frame.size.height = -offsetY + 20;

            _expandZoomImageView.frame = frame;

        }

     KActivityDetailHeadH 此处是tableView上面图片的高度

    1
  • 相关阅读:
    喜马拉雅第三方客户端开发(接口和接口数据解析)。
    jquery-easyui中datagrid扩展,隐藏显示表头功能
    backbone ,jQuery-easyui,knockoutjs的整合使用
    WPF中的瀑布流布局(TilePanel)控件
    使用this.$refs['formName'].resetFields()无法重置表单
    js获取json对象的key值
    Hash表算法详解
    Redis入门
    ASP.Net 下载大文件的实现
    后端生成二维码
  • 原文地址:https://www.cnblogs.com/fantasy3588/p/5516572.html
Copyright © 2011-2022 走看看