1

我在互联网上看到很多人都在问如何在边缘淡化他们的 tableview 的问题。有一些解决方案几乎可以工作。一个例子是:

CAGradientLayer *maskLayer = [CAGradientLayer layer];

CGColorRef outerColor = [UIColor colorWithWhite:1.0 alpha:1.0].CGColor;
CGColorRef innerColor = [UIColor colorWithWhite:1.0 alpha:0.0].CGColor;

maskLayer.colors = [NSArray arrayWithObjects:(__bridge id)innerColor, (__bridge id)outerColor, nil];
maskLayer.locations = [NSArray arrayWithObjects:
                       [NSNumber numberWithFloat:0.8], 
                       [NSNumber numberWithFloat:1.0], nil];


maskLayer.bounds = CGRectMake(0, 0,
                              self.historyTable.frame.size.width,
                              self.historyTable.frame.size.height + self.headerLabel.frame.size.height);
maskLayer.anchorPoint = CGPointZero;

[self.view.layer addSublayer:maskLayer];

此代码运行良好,但它的问题是它只能将其淡化为纯色。我想要做的是淡出背景图像(它将有图案并且可以将屏幕更改为屏幕)。有没有办法做到这一点?

谢谢。

4

1 回答 1

0

Had the same problem, assuming we are talking about the Cocoanetics tutorial, replace your last line:

[self.view.layer addSublayer:maskLayer];

With this one:

self.historyTable.layer.mask = maskLayer;

Basically skip the last step of the tutorial but attach the mask to the tableView's layer.

Also check this answer for complete solution including handling top and bottom of table..

于 2014-01-21T14:40:52.940 回答