カスタム UITableViewCell があります。xib ファイルは次のようになります。
セルは、選択することで開いたり閉じたりできます。セルを閉じると、タイトル ラベルと上部の背景画像のみが表示されます。開いた状態と閉じた状態の、シミュレーターでのテーブル ビューは次のようになります。
丸みを帯びた角をどのように処理するかを理解しようとしています。現在、セルが最初、最後、または中間のセルであるかどうかを確認し、マスクを適用しています。
if (row == 0)
{
// Create the path (with only the top corners rounded)
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:cell.titleBackgroundImageView.bounds
byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight)
cornerRadii:CGSizeMake(10.0, 10.0)];
// Create the shape layer and set its path
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = cell.titleBackgroundImageView.bounds;
maskLayer.path = maskPath.CGPath;
// Set the newly created shape layer as the mask for the image view's layer
cell.titleBackgroundImageView.layer.mask = maskLayer;
cell.bodyBackgroundImageView.layer.mask = nil;
}
else if ((row + 1) == [itemsForSection count])
{
// Create the path (with only the bottom corners rounded)
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:cell.titleBackgroundImageView.bounds
byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight)
cornerRadii:CGSizeMake(10.0, 10.0)];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
// Create the shape layer and set its path
BOOL isOpened = [[[self.cellOpenedStatusMutableDictionary objectForKey:sectionTitle] objectAtIndex:row] boolValue];
if (isOpened)
{
cell.titleBackgroundImageView.layer.mask = nil;
}
else
{
maskLayer.frame = cell.titleBackgroundImageView.bounds;
maskLayer.path = maskPath.CGPath;
cell.titleBackgroundImageView.layer.mask = maskLayer;
}
// Create the path (with only the bottom corners rounded)
maskPath = [UIBezierPath bezierPathWithRoundedRect:cell.bodyBackgroundImageView.bounds
byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight)
cornerRadii:CGSizeMake(10.0, 10.0)];
// Create the shape layer and set its path
maskLayer = [CAShapeLayer layer];
maskLayer.frame = cell.titleBackgroundImageView.bounds;
maskLayer.path = maskPath.CGPath;
cell.bodyBackgroundImageView.layer.mask = maskLayer;
}
else
{
cell.titleBackgroundImageView.layer.mask = nil;
cell.bodyBackgroundImageView.layer.mask = nil;
}
しかし、ご覧のとおり、一番下のセルではうまく機能しません。テーブル ビューの境界線が見えなくなります。
どうすればこの問題を解決できますか?