下拉放大, 上推漸變

2016-08-20 13_11_15.gif
屬性
@property (nonatomic, strong)UITableView *tableView;
@property (nonatomic, strong)UIView *backGroundView;
@property (nonatomic, strong)UIImageView *imageView;
@property (nonatomic, strong)UIImageView *barImageView;```
######要在導(dǎo)航欄上顯示圖片

[self.navigationController.navigationBar setBackgroundImage:[UIImage alloc] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];

######創(chuàng)建TableView
  • (void)creatTableView {
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, -64, self.view.bounds.size.width, self.view.bounds.size.height + 64)];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    _tableView.tableHeaderView = [self creatTableViewHeaderView];
    self.barImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, -20, WIDTH, 64)];
    _barImageView.image = [UIImage imageNamed:@"tts-navbar"];
    [self.navigationController.navigationBar addSubview:_barImageView];
    self.navigationItem.title = @"導(dǎo)航欄";
    }
  • (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 20;
    }
  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.textLabel.text = [NSString stringWithFormat:@"cell = %ld", (long)indexPath.row];
    return cell;
    }
######將圖片放在頭視圖上
  • (UIView *)creatTableViewHeaderView {
    self.backGroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 200)];
    self.imageView = [[UIImageView alloc] initWithFrame:self.backGroundView.bounds];
    _imageView.image = [UIImage imageNamed:@"1.jpg"];
    [self.backGroundView addSubview:_imageView];
    return _backGroundView;
    }
#####上推漸變, 下拉放大的設(shè)置
  • (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    // 上推漸變
    CGFloat offset_Y = scrollView.contentOffset.y;
    CGFloat alpha = (offset_Y + 64) / 200.0f;
    self.barImageView.alpha = alpha;
    // 下拉放大
    if (offset_Y < -64) {
    CGFloat add_height = -(offset_Y + 64);
    CGFloat scale = (200 + add_height) / 200.0f;
    self.imageView.frame = CGRectMake(-(WIDTH * scale - WIDTH) / 2.0f, -add_height, WIDTH * scale, 200 + add_height);
    NSLog(@"%f", scale);
    }
    }

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

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

  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 15,833評論 4 61
  • 轉(zhuǎn)載自:https://github.com/Tim9Liu9/TimLiu-iOS 目錄 UI下拉刷新模糊效果A...
    袁俊亮技術(shù)博客閱讀 12,154評論 9 105
  • 國內(nèi)英語教材已經(jīng)有很多版本了,外研版、人教版、牛津版,有的學(xué)校還有自己的校本教材,也算五花八門了,可是,沒有對比就...
    Sunnywinter777閱讀 1,030評論 5 3
  • China’s Weibo eclipses rival Twitter’s market capitalizat...
    huuila閱讀 341評論 0 0
  • 初五迎財(cái)神,從范蠡想到了《史記》的《貨殖列傳》,之前買的是中華書局的繁體非注解版,沒法看,束之高閣,還是找來度娘。...
    掌門_艾老師閱讀 401評論 0 1

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