Masonry-拉伸头视图
#import "ViewController.h"
#import "Masonry.h"
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong) UITableView *tableV;
//imgeV高度的约束 约束也是一个对象
@property (nonatomic,strong) MASConstraint *heightConstraint;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self createTableView];
[self createHeaderImage];
}
- (void)createTableView{
self.tableV = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
self.tableV.delegate = self;
self.tableV.dataSource = self;
[self.tableV registerClass:[UITableViewCell class] forCellReuseIdentifier:@"id"];
[self.view addSubview:self.tableV];
//contentInset内边距
self.tableV.contentInset = UIEdgeInsetsMake(235, 0, 0, 0);
//透明
self.tableV.backgroundColor = [UIColor clearColor];
}
- (void)createHeaderImage{
UIImageView *imageV = [[UIImageView alloc]init];
//按比例布局 ScaleAspectFill按照比例填充 高度变化 宽也会按比例变化(放大或收缩)
imageV.contentMode = UIViewContentModeScaleAspectFill;
imageV.image = [UIImage imageNamed:@"8副本"];
//把imageV放在tableV的下面
[self.view insertSubview:imageV aboveSubview:self.tableV];
[imageV mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.mas_equalTo(0);
//高的约束
self.heightConstraint = make.height.mas_equalTo(235);
}];
}
//scrollView滚动时,就调用该方法。任何offset值改变都调用该方法。即滚动过程中 调用
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
if (scrollView.contentOffset.y < -235) {
//self.heightConstraint == make.height
self.heightConstraint.mas_equalTo(-scrollView.contentOffset.y);
}
}
// 当scrollView缩放时,调用该方法。在缩放过程中,回多次调用
//- (void)scrollViewDidZoom:(UIScrollView *)scrollView{
//
// NSLog(@"scrollViewDidScroll");
// float value=scrollView.zoomScale;
// NSLog(@"%f",value);
//}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 20;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"id" forIndexPath:indexPath];
cell.textLabel.text = [NSString stringWithFormat:@"第%ld行",(long)indexPath.row];
return cell;
}
@end
Masonry-拉伸头视图.png
网友评论