• 向下放大,向上悬停效果


    //
    //  ViewController.m
    //  detailView
    //
    //  Created by 殷婷婷 on 16/5/20.
    //  Copyright © 2016年 yin. All rights reserved.
    //
    
    #import "ViewController.h"
    
    @interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
    @property (weak, nonatomic) IBOutlet UITableView *tableView;
    
    @property(nonatomic,weak) UIImageView *imgV;
    @end
    static CGFloat tableHeaderViewH = 300;
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        
        UIImageView *imgV = [[UIImageView alloc]initWithFrame:CGRectMake(0, -tableHeaderViewH, self.view.bounds.size.width, tableHeaderViewH)];
        imgV.image = [UIImage imageNamed:@"1.jpg"];
        imgV.contentMode = UIViewContentModeScaleAspectFill;
        //self.tableView.tableHeaderView = imgV;
        self.imgV = imgV;
        [self.tableView insertSubview:imgV atIndex:0];
        self.tableView.contentInset = UIEdgeInsetsMake(tableHeaderViewH * 0.5, 0, 0, 0);
    //此时tableview的contentoffset.y = - tableHeaderViewH * 0.5,scrollDidscroll打印。。。 }
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 20; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static int i = 1; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; if (!cell) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"]; } cell.textLabel.text = [NSString stringWithFormat:@"%d",i]; i++; return cell; } - (void)scrollViewDidScroll:(UIScrollView *)scrollView{ NSLog(@"%f", -scrollView.contentOffset.y - tableHeaderViewH * 0.5); CGFloat delta = -scrollView.contentOffset.y - tableHeaderViewH * 0.5; if (delta <= 0) { [self.tableView bringSubviewToFront:self.imgV]; CGRect frame = self.imgV.frame; frame.origin.y = -tableHeaderViewH - delta; self.imgV.frame = frame; return; } [self.tableView insertSubview:self.imgV atIndex:0]; CGRect frame = self.imgV.frame; frame.size.height = tableHeaderViewH + delta; self.imgV.frame = frame; } @end
  • 相关阅读:
    前端面试题整合(JS基础篇)(二)
    前端面试题整合(JS基础篇)(一)
    python学习笔记(六)— 模块
    python学习笔记(五)— 内置函数
    python学习笔记(四)— 补充
    python学习笔记(四)— 函数
    python学习笔记(二)— 集合
    python学习笔记(三)— 文件操作
    python学习笔记(二)— 字典(Dictionary)
    python学习笔记(二)— 元组(tuple)
  • 原文地址:https://www.cnblogs.com/yintingting/p/5512356.html
Copyright © 2020-2023  润新知