zoukankan      html  css  js  c++  java
  • //头部拉伸效果

    //头部拉伸效果

    #import "ViewController.h"

    @interface ViewController ()<UITableViewDelegate,UITableViewDataSource>

    @property (nonatomic) UITableView *tabelView;

    @property (nonatomic, copy) NSArray *dataSource;

    @end

    @implementation ViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        [self createUI];

    }

    -(void)createUI{

        

        self.dataSource = @[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"1",@"2",@"3",@"4",@"5",@"6",@"7"];

        

        self.tabelView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];

        self.tabelView.delegate = self;

        self.tabelView.dataSource = self;

        self.tabelView.contentInset = UIEdgeInsetsMake(200, 0, 0, 0);

        [self.view addSubview:self.tabelView];

        

        

        UIImageView *headerImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, -200, self.view.frame.size.width, 200)];

        headerImageView.image = [UIImage imageNamed:@"mineHeaderBackImage"];

        headerImageView.tag = 101;

    //    headerImageView.contentMode = UIViewContentModeScaleToFill;//上下填充

        headerImageView.contentMode = UIViewContentModeScaleAspectFill;//上下左右等比例填充

        [self.tabelView addSubview:headerImageView];

    }

    -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

        return 1;

    }

    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

        return self.dataSource.count;

    }

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"string"];

        if (cell==nil) {

            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"string"];

        }

        cell.textLabel.text = self.dataSource[indexPath.row];

        return cell;

    }

    -(void)scrollViewDidScroll:(UIScrollView *)scrollView{

        CGRect rect = [self.view viewWithTag:101].frame;

        CGPoint point = scrollView.contentOffset;

        if (point.y < -200) {

            //处于拉伸状态

            rect.origin.y = point.y;

            rect.size.height = -point.y;

            [self.view viewWithTag:101].frame = rect;

        }

        NSLog(@"point.y  %f",point.y);

    }

    - (void)didReceiveMemoryWarning {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

    @end

  • 相关阅读:
    vim初试(Hello World)
    CSP201809-2 买菜(超简单的方法!!)
    CSP202006-2 稀疏向量
    CSP202012-2 期末预测之最佳阈值
    浮点数表示
    结构体
    全排列-康托展开及逆展开
    CA-031 上手Games101环境 Games101环境怎么配置
    计算机图形学 实验四 AET算法
    计算机图形学 实验三 梁氏裁剪算法
  • 原文地址:https://www.cnblogs.com/lrr0618/p/5756031.html
Copyright © 2011-2022 走看看