#import "ViewController.h"
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>{
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 图片下拉变大
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 先看效果: 分析思路,当我往下拉的时候图片定在navigationbar下面,图片拉伸,而且cell和图片间的间隙...
- 现在很多app设置了这样的效果,如何实现这一效果呢,其实只需要简单的两个方法,那么我们直接上代码 首先我们在sto...