TableView-下拉頂部圖片變大

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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容