4

だから私はUIViewプロトタイプを持っていUITableViewCellます。そのビューのawakeFromNibメソッドには、影を作成する次のコードがあります

CALayer *layer = self.layer;

layer.cornerRadius = 5.0f;

// Makes shadow for each cell in all and nearby table views.

CGSize size = self.bounds.size;
CGFloat curlFactor = 15.0f;
CGFloat shadowDepth = 5.0f;

UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(0.0f, 0.0f)];
[path addLineToPoint:CGPointMake(size.width, 0.0f)];
[path addLineToPoint:CGPointMake(size.width, size.height + shadowDepth)];
[path addCurveToPoint:CGPointMake(0.0f, size.height + shadowDepth)
        controlPoint1:CGPointMake(size.width - curlFactor, size.height + shadowDepth - curlFactor)
        controlPoint2:CGPointMake(curlFactor, size.height + shadowDepth - curlFactor)];

self.layer.shadowColor = [UIColor blackColor].CGColor;
self.layer.shadowOpacity = 0.3f;
self.layer.shadowOffset = CGSizeMake(2.0f, 7.0f);
self.layer.shadowRadius = 2.0f;
self.layer.masksToBounds = NO;
self.layer.shadowPath =  path.CGPath; //Sets a path for the shadow. Greatly enhances performance.

問題は、影がすべてではなく一部のセルにのみ表示され、時々ランダムに見えることです。コードを入れてみましたが、そこでもうまくviewWillAppearいきviewDidAppearませんでした。これを引き起こしている可能性のあるものの手がかりを誰かが持っていますか?

4

1 に答える 1

3

問題は、ドロップ シャドウが欠落しているのではなく、他のセルと重なっているだけであることに最終的に気付きました。

したがって、この回答で問題を解決できます(sendSubviewToBack:この場合は必要になります)。

参考までに、iOS 6の新しいUICollectionViewを使用すると、セルの z インデックスをより詳細に制御できます。iOS 6 より前のサポートについては、PSTCollectionViewが優れた代替手段です。

于 2013-01-11T03:41:16.830 に答える