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
  • 相关阅读:
    oracle体系结构
    Oracle表连接(转)
    Oracle的RBO和CBO
    Linux下安装Tomcat服务器和部署Web应用
    动态创建selectjs 操作select和option
    JS中如何获取<Select>中value和text的值
    原生JavaScript事件详解
    动态添加select的option
    js 动态加载事件的几种方法总结
    js实现select动态添加option
  • 原文地址:https://www.cnblogs.com/fantasy3588/p/5516572.html
Copyright © 2011-2022 走看看