美文网首页
2019-08-29 透明cell

2019-08-29 透明cell

作者: 你也想起舞吧 | 来源:发表于2019-12-19 16:34 被阅读0次
    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;
        }
    }

    相关文章

      网友评论

          本文标题:2019-08-29 透明cell

          本文链接:https://www.haomeiwen.com/subject/kziiectx.html