您的位置:首页 > 产品设计 > UI/UE

iOS——UITableVew 头部图片下拉放大

2015-07-09 14:59 573 查看
#import "MyViewController.h"

CGFloat const imageW=320;

CGFloat const imageH=320;

CGFloat const inseTop=150;

@interface MyViewController ()

@property (nonatomic ,strong)UIImageView *myimageView;

@end

@implementation MyViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    

   

    self.tableView.contentInset=UIEdgeInsetsMake(inseTop, 0, 0, 0);

    self.myimageView=[[UIImageView alloc]init];

    self.myimageView.image=[UIImage imageNamed:@"1436262350712853.jpg"];

    self.myimageView.frame=CGRectMake(0, -inseTop, imageW, imageH);

    

    //设置内容模式,也是核心代码

    self.myimageView.contentMode=UIViewContentModeScaleAspectFill;

    [self.tableView insertSubview:self.myimageView atIndex:0];

}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

#pragma mark - 核心代码

-(void)scrollViewDidScroll:(UIScrollView *)scrollView

{

   

    CGFloat dragdelta=-inseTop-scrollView.contentOffset.y;

    if (dragdelta<0)

    {

        dragdelta=0;

    }

    

    CGRect new=self.myimageView.frame;

    new.size.height=inseTop+dragdelta;

    self.myimageView.frame=new;

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    

    return 20;

}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString *ID=@"id";

    

    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:ID];

    if (cell==nil)

    {

        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];

    }

    

    NSString *title=[NSString stringWithFormat:@"哈哈:%ld",indexPath.row];

    cell.textLabel.text=title;

    return cell;

}

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  下拉放大