Mask all views below a UIView except background

五迷三道 提交于 2019-12-25 07:47:18

问题


I have a transparent section header in a UITableView, which should let the cells scroll behind it but show the background image which is behind the tableview instead of the cells. I need a way to apply some sort of clipping mask to the section header which would make any views which go beneath it transparent, or something which shows the appropriate part of the background image as the header's background and follows when the header moves.

I have seen this How to mask UITableViewCells underneath a UITableView Transparent Header, but it doesn't quite work as advertised, and is generally a bad implementation.

I have also tried this:

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor);
    CGContextFillRect(context, self.frame);
    CGContextSetBlendMode(context, kCGBlendModeClear);
}

in the section header's subclass, but this just shows the view with a black background.

If you need more explanation, here is what I have:

http://imgur.com/a/YM5Us

and here is what I want to achieve:

http://imgur.com/a/o9CgL


回答1:


I've done a similar task in a game. SpriteKit offers excellent performance on this since it has this as a built-in feature.

You can mix SpriteKit with UIKit but using SpriteKit as a background & not the other way around as you need, since SKView cannot have transparent background.

In my opinion you should here create a custom header view or to change the displaying of the cell.



来源:https://stackoverflow.com/questions/42066123/mask-all-views-below-a-uiview-except-background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!