如何在UITableView透明标题下掩盖UITableViewCells [英] How to mask UITableViewCells underneath a UITableView Transparent Header

查看:163
本文介绍了如何在UITableView透明标题下掩盖UITableViewCells的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要标题来屏蔽单元格,而不是背景。

I want the header to mask the cells, but not the background.

我有一个带透明标题的UITableView和类似于Apple的通知中心的单元格(当你滑动时按下iPhone上的状态栏)。我无法弄清楚如何屏蔽单元格,以便在滚动时它们不会显示在标题下方。

I have a UITableView with transparent headers and cells similar to Apple's Notification Center (when you swipe down on the status bar on your iPhone). I can't figure out how to mask the cells so they don't show up underneath the header when it scrolls.

我已经尝试更改tableview的contentInsets,并且我尝试将标题View的框架更改为负面原点。

I've tried changing the contentInsets of the tableview, and I've tried changing the frame of the header View to a negative origin.

推荐答案

尝试创建 UITableviewCell 的子类并添加这些方法

Try to make a subclass of UITableviewCell and add these methods

- (void)maskCellFromTop:(CGFloat)margin {
    self.layer.mask = [self visibilityMaskWithLocation:margin/self.frame.size.height];
    self.layer.masksToBounds = YES;
}

- (CAGradientLayer *)visibilityMaskWithLocation:(CGFloat)location {
    CAGradientLayer *mask = [CAGradientLayer layer];
    mask.frame = self.bounds;
    mask.colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithWhite:1 alpha:0] CGColor], (id)[[UIColor colorWithWhite:1 alpha:1] CGColor], nil];
    mask.locations = [NSArray arrayWithObjects:[NSNumber numberWithFloat:location], [NSNumber numberWithFloat:location], nil];
    return mask;
}

并在 UITableView

#pragma mark - UIScrollViewDelegate

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    for (iNotifyTableViewCell *cell in self.visibleCells) {
        CGFloat hiddenFrameHeight = scrollView.contentOffset.y + [iNotifyHeaderView height] - cell.frame.origin.y;
        if (hiddenFrameHeight >= 0 || hiddenFrameHeight <= cell.frame.size.height) {
            [cell maskCellFromTop:hiddenFrameHeight];
        }
    }
}

*请注意 [iNotifyHeaderView height] HeaderView 的高度。并使用 #import< QuartzCore / QuartzCore.h> 作为自定义单元格。

*Note that [iNotifyHeaderView height] is the height of the HeaderView. and use #import <QuartzCore/QuartzCore.h> for the custom cell.

这篇关于如何在UITableView透明标题下掩盖UITableViewCells的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆