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
  • 相关阅读:
    Windows2012 cannot access netapp CIFS share
    Import SHA2 SSL cert to Windows IIS7
    IE11登陆交行网银崩溃
    Understanding and Managing SMTP Virtual Servers
    IIS SMTP Queue stuck
    C#夯实基础之多线程三:线程的优先级
    C#夯实基础之多线程二:主线程、前台线程与后台线程
    ORA-00257: archiver error. Connect internal only, until freed.
    C#夯实基础之多线程一:初识多线程
    在Oracle中恢复被DROP掉的表
  • 原文地址:https://www.cnblogs.com/fantasy3588/p/5516572.html
Copyright © 2011-2022 走看看