cell.gif
透明cell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
//加上 dispatch_after 能够获取到 设置 行高 后 cell 的高度,不加 cell 还是 原来的 bounds
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self initUI];
});
}
return self;
}
- (void)initUI {
UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:self.bounds];
scrollView.contentSize = CGSizeMake(self.bounds.size.width, self.bounds.size.height);
scrollView.alwaysBounceVertical = YES;
[self.contentView addSubview:scrollView];
self.scrollView.userInteractionEnabled = NO;
self.scrollView = scrollView;
UIImageView *imageView = [[UIImageView alloc] init];
imageView.image = [UIImage imageNamed:@"timg.jpg"];
CGFloat height = imageView.image.size.height;
imageView.frame = CGRectMake(0, - height, kWidth, height);//根据图片尺寸设计坐标
[scrollView addSubview:imageView];
}
- (void)setContendOffset:(CGFloat)contendOffset{
_offset = contendOffset;
[self.scrollView setContentOffset:CGPointMake(0, -_offset) animated:NO];//注意不要动画!!!
}
ViewController
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CELLREUSE = @"cell_reuse";
//第6个位透明cell
if (indexPath.row == 5) {
ShowCell *cell = [[SHowCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"showcell"];
return cell;
}else {
MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CELLREUSE];
if (!cell) {
cell = [[MyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CELLREUSE];
}
return cell;
}
}
//实现scrollView滚动代理方法
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat contentPointY = 5 * cellHeight - kHeight;
CGFloat contentOffSet = scrollView.contentOffset.y;
if (contentOffSet >= contentPointY && contentOffSet <= 5 * cellHeight) {
NSIndexPath *indexs = [NSIndexPath indexPathForRow:5 inSection:0];
SowCell *showcell = [self.tableView cellForRowAtIndexPath:indexs];
showcell.contendOffset = contentOffSet - contentPointY;
}
}
网友评论