码迷,mamicode.com
首页 > 其他好文 > 详细

向下放大,向上悬停效果

时间:2016-05-20 16:00:25      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:

//
//  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

 

向下放大,向上悬停效果

标签:

原文地址:http://www.cnblogs.com/yintingting/p/5512356.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!