zoukankan      html  css  js  c++  java
  • 第十一篇、UITableView headerview下拉放大

    核心代码:

    -(void)createTableViewHeaderView{
    
    
        _tableViewHeaderView = [[UIView alloc] initWithFrame:(CGRectMake(0, 0, ScreenWidth, _imageHeight))];
        _headerBackView = [[UIImageView alloc] init];
    
    //    背景图
        _headerBackView.frame = CGRectMake(0, 0, ScreenWidth, _imageHeight);
        _headerBackView.image = [UIImage imageNamed:@"bj1@2x.jpg"];
    
        [_tableViewHeaderView addSubview:_headerBackView];
        _photoImageView = [[UIImageView alloc] initWithFrame:CGRectMake((ScreenWidth - 62)/2, 15 , 62 , 62 )];
        [self.tableViewHeaderView addSubview:self.photoImageView];
        _photoImageView.layer.cornerRadius = 31 ;
        _photoImageView.layer.masksToBounds = YES;
    
        _photoImageView.image = [UIImage imageNamed:@"2.jpg"];
    
        _userNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, _photoImageView.frame.origin.y + _photoImageView.frame.size.height + 8 , ScreenWidth, 20 )];
        _userNameLabel.font = [UIFont fontWithName:@"iconfont" size:16 ];
        _userNameLabel.text = @"纳兰性德";
        _userNameLabel.textAlignment = 1;
        _userNameLabel.font = [UIFont systemFontOfSize:16  ];
        _userNameLabel.textColor = [UIColor whiteColor];
        [_tableViewHeaderView addSubview:self.userNameLabel];
    
        _introduceLabel = [[UILabel alloc] initWithFrame:CGRectMake((ScreenWidth - 229 )/2, _userNameLabel.frame.origin.y + _userNameLabel.frame.size.height + 10 , 229 , 16 )];
        _introduceLabel.alpha = .7;
        _introduceLabel.text = @"人生若只如初见,何事秋风悲画扇";
        _introduceLabel.textAlignment = 1;
        _introduceLabel.font = [UIFont systemFontOfSize:12 ];
        _introduceLabel.textColor = _userNameLabel.textColor;
        [_tableViewHeaderView addSubview:self.introduceLabel];
    
        self.tableView.tableHeaderView = _tableViewHeaderView;
    
    }
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
    
        CGFloat width = self.view.frame.size.width; // 图片宽度
        CGFloat yOffset = scrollView.contentOffset.y;  // 偏移的y值
        if (yOffset < 0) {
            CGFloat totalOffset = _imageHeight + ABS(yOffset);
            CGFloat f = totalOffset / _imageHeight;
            self.headerBackView.frame =  CGRectMake(- (width * f - width) / 2, yOffset, width * f, totalOffset); //拉伸后的图片的frame应该是同比例缩放。
        }
    
    
    }
  • 相关阅读:
    安全传输平台项目扩展——keymngserver重构-硬件扩展
    安全传输平台项目扩展——C复习-C++复习-keymngclient重构
    安全传输平台项目——客户端代码移植-项目模块总结
    安全传输平台项目——配置管理终端-读写数据库
    根号分治刷题记录
    使用netsh命令来管理IP安全策略
    关于make_shared无法访问非公有构造函数的解决方法
    两两交换链表中的节点-递归解法
    Spring 的 AOP 简介
    Spring IOC和DI 注解开发
  • 原文地址:https://www.cnblogs.com/HJQ2016/p/6055868.html
Copyright © 2011-2022 走看看