iOS 图片下拉变大


#import "ViewController.h"

@interface ViewController (){
    UITableView * _TabView;
    NSArray * MessageArr;
    UITapGestureRecognizer * tapGest;
}
#define KHIGHT  200
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    
    MessageArr =[NSArray arrayWithObjects:@"abc",@"abc",@"abc", nil];
    
    _TabView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    _TabView.delegate = self;
    _TabView.dataSource = self;
    
    [self.view addSubview:_TabView];
    
    
    _TabView.contentInset = UIEdgeInsetsMake(KHIGHT, 0, 0, 0);
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, -KHIGHT, [UIScreen mainScreen].bounds.size.width, KHIGHT)];
    
    imageView.image = [UIImage imageNamed:@"3.jpg"];
    //图片设置为填充模式
    imageView.contentMode = UIViewContentModeScaleAspectFill;
    //剪切到边界
    imageView.clipsToBounds = YES;
    imageView.tag = 101;
    
    UIImageView * IMG = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"3.jpg"]];
    IMG.frame = CGRectMake(self.view.frame.size.width/2-30,-30, 60, 60);
    IMG.layer.cornerRadius = 30;
    IMG.layer.masksToBounds = YES;
    //给图片添加点击事件
    tapGest = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(PressImg)];
    //将图片与点击事件绑定
    [IMG addGestureRecognizer:tapGest];
    //允许图片被用户点击
    IMG.userInteractionEnabled=YES;
    
    [_TabView addSubview:imageView];
    [_TabView addSubview:IMG];
}
//设置tableview 的行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return MessageArr.count;
}
//设置
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * cellid = @"cellid";
    
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellid];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellid];
        cell.textLabel.text = [MessageArr objectAtIndex:indexPath.row];
    }
    //取消选中变灰
//    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    
    CGPoint point = scrollView.contentOffset;
    if (point.y < -KHIGHT) {
        CGRect rect = [_TabView viewWithTag:101].frame;
        rect.origin.y = point.y;
        rect.size.height = -point.y;
        [_TabView viewWithTag:101].frame = rect;
    }
}
-(void)PressImg{
    
    NSLog(@"点击了图片");
}
@end


你可能感兴趣的:(iOS 图片下拉变大)