美文网首页
TableView-下拉顶部图片变大

TableView-下拉顶部图片变大

作者: 欲速则不达 | 来源:发表于2016-09-19 10:00 被阅读23次

import "ViewController.h"

/**

  • 屏幕宽度
    */

define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)

/**

  • 屏幕高度
    */

define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)

define ImgHight 200.0f

@interface ViewController ()<UITableViewDataSource,UITableViewDelegate,UIScrollViewDelegate>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIImageView *imgView;

@end

@implementation ViewController

  • (void)viewDidLoad {
    [super viewDidLoad];

    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.contentInset = UIEdgeInsetsMake(ImgHight, 0, 0, 0);
    [self.view addSubview:_tableView];

    _imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, -ImgHight, SCREEN_WIDTH, ImgHight)];
    _imgView.image = [UIImage imageNamed:@"3.jpg"];
    _imgView.backgroundColor = [UIColor greenColor];
    [_tableView addSubview:_imgView];
    }

  • (void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
    CGPoint point = scrollView.contentOffset;
    if (point.y < -ImgHight) {
    CGRect rect = _imgView.frame;
    rect.origin.y = point.y;
    rect.size.height = -point.y;
    _imgView.frame = rect;
    }
    }

  • (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
    return 10;
    }

  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellID"];
    if (!cell) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellID"];
    }

    return cell;
    }

  • (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    }

@end

相关文章

网友评论

      本文标题:TableView-下拉顶部图片变大

      本文链接:https://www.haomeiwen.com/subject/szrmettx.html