4

UITableViewCell がその境界にクリッピングすることで、他のみんなと同じ問題を抱えています。他の誰かが正しく指摘したように、セルの contentView には新しいスーパービューがあります。だから私はこれをしました:

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *cellIdentifier = @"HomeTableViewCell";
    ItemCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if(!cell)
    {
        cell = [[ItemCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
       //add views here as subviews to cell.contentView. Set them tags and retrieve later.
    }

    cell.clipsToBounds  = FALSE;
    cell.layer.masksToBounds = FALSE;
    cell.contentView.clipsToBounds = FALSE;
    cell.contentView.layer.masksToBounds = FALSE;
    cell.contentView.superview.clipsToBounds = FALSE;
    cell.contentView.superview.layer.masksToBounds = FALSE;

    [self loadCell:cell inTable:tableView atIndexPath:indexPath];

    return cell;
}

loadCell: inTable: atIndexPath:タグによってセルのサブビューを取得し、適切なコンテンツをロードします。それはうまくいっています。clipToBoundsまたはの他の言及はありませんlayer.masksToBounds。BUT:選択したセルをリロードすると、一時的に境界にクリップされ、上記のコードにヒットして正しくなります。したがって、約1〜2秒間、セルが切り取られます。これが内部で起こっていることItemCellです。このクラスを作成して、何がそのclipToBoundsプロパティを TRUE にするかを確認しました。

@implementation ItemCell

- (id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]))
    {
        [self addObserver:self forKeyPath:@"layer.masksToBounds"    options:NSKeyValueObservingOptionNew context:nil];
        [self addObserver:self forKeyPath:@"clipsToBounds"          options:NSKeyValueObservingOptionNew context:nil];
    }

    return self;
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    NSNumber *nr = [change objectForKey:@"new"];
    if(nr.intValue)
    {
        self.clipsToBounds = FALSE;        // STAY FALSE!!
        self.layer.masksToBounds = FALSE;
    }
}

TRUE になったときに FALSE にしても、クリップされた/クリップされていない間にギャップがあります。それはちょうど小さいです。iOS6では発生しませんでした。これは、プロパティが TRUE になったときのスタック トレースです。自動的に呼び出されるclipsToBoundsことがわかります。CALayer setMasksToBounds

ここに画像の説明を入力

誰かが修正のアイデアを持っていますか?? ありがとうございました!

4

1 に答える 1

3

私は今、私のコードでこの問題を修正したようです。最初に、クリッピングなどに関して Interface Builder ですべてが設定されていることを確認します。次に、次のコードのすべてまたは一部の組み合わせが必要と思われます。

tableView:cellForRowAtIndexPath:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];

    //ios7 hacks
    [cell.contentView.superview setClipsToBounds:NO];
    [cell.contentView setClipsToBounds:NO];
    [cell setClipsToBounds:NO];
    return cell;
}

tableView:willDisplayCell:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    //ios 7 cell background fix
    [cell.contentView.superview setClipsToBounds:NO];
    [cell.contentView setClipsToBounds:NO];
    [cell setClipsToBounds:NO];
    [cell setBackgroundColor:[UIColor clearColor]];
    //ios 7 content clipping fix
    [cell.contentView.superview setClipsToBounds:NO];
    [cell.contentView setClipsToBounds:NO];
    [cell setClipsToBounds:NO];
}
于 2013-12-01T19:46:22.507 に答える