zoukankan      html  css  js  c++  java
  • 向下放大,向上悬停效果

    //
    //  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
  • 相关阅读:
    Simple ASP.NET CORE 2.2 App +Vue JS
    Upload Image to .NET Core 2.1 API
    Nginx支持WebSocket服务
    DD打卡
    Asp.net Core 源码-PagedList<T>
    Asp.net Core 源码-UrlExtensions
    Asp.net Core 源码-SessionExtensions
    树莓派资源集合
    frp内网穿透
    Nuget包含cssjs等资源文件
  • 原文地址:https://www.cnblogs.com/yintingting/p/5512356.html
Copyright © 2011-2022 走看看