13

削除ボタンを非表示にするとセルがアニメーション化されないため、何が欠けているのか知りたいです。削除ボタンのアニメーションが終了する前に、ラベルが元の位置に戻ります。

ラウンド編集ビューをタップして削除ボタンを表示すると、ラベルアニメーションが機能します。

削除ボタンが表示されるセルのスクリーンショット

ただし、もう一度タップして削除ボタンを非表示にすると、ラベルの動きがアニメーション化されません。

削除ボタンが消えるセルのスクリーンショット

注:これらのスクリーンショットは、次のコードから作成されたものではありません。しかし、彼らは問題を示しています。

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    homeCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[homeCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }

    // Set up the cell
    Consumed *drinkObj = [self.appDelegate.consumedDrinksArray objectAtIndex:indexPath.row];        
    cell.titleLabel.text = drinkObj.drinkName;
    NSString *detailTextTime = [NSDate stringFromDate:drinkObj.dateConsumed withFormat:@"h:mma"];

    NSString *detailTextrelative = [relativeDateTransformer transformedValue:drinkObj.dateConsumed];

    NSString *detailText =  [NSString stringWithFormat:@"%@ %@ ", detailTextTime,detailTextrelative];
    cell.timeLabel.text = detailText;

    cell.stdDLabel.text = @"999.0"; //[NSString stringWithFormat:@"%@", drinkObj.standardDrinks];
    cell.stdDLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
    cell.titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
    cell.timeLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
4

4 に答える 4

7

編集:バグは私が最初に理解したものとは異なることがわかります。私の答えを訂正しましょう。私が正しい場合、削除ボタンはアニメーションで正しく消えますが、コンテンツビューはアニメーション化せずにサイズ変更されます(ボタンのアニメーションの後ろに移動します)。

この場合、アニメーションを自分で管理する必要があります。ローテーションをサポートしていないと仮定して、コードを提供します。ローテーションをサポートしたい場合は、より多くのコードが必要になります:-)

これがサンプルプロジェクトです(標準のマスター/詳細xcodeテンプレートを使用したため、多くのコードがあります。カスタムセルのみを見てください):サンプルプロジェクト

コードに適用するには:

まず、セルの右側にあるラベルの自動サイズ変更マスクを、左側に固定するように変更します。

正しいラベルがstdDLabelかどうかはわかりませんが、それを想定します

// if the right margin is flexible, the left-top-bottom are fixed
cell.stdDLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;

setEditing:animated:セルサブクラスで、次のようにメソッドをオーバーライドします。

-(void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    // this is an array of the labels / view that you want to animate
    NSArray *objectsToMove = @[self.stdDLabel];
    // this is the amount of pixel to move - the width of the delete button
    float pixelToMove = 70.0f;

    float animationDuration = 0.3f;

    // calculating the delta. If set editing, move from right to left. otherwise, from left to right
    float delta = (editing) ? -pixelToMove : pixelToMove;

    // put the move code in a block for avoid repeating code in the if
    void (^moveBlock)() = ^{
        for (UIView *view in objectsToMove) {
            view.center = CGPointMake(view.center.x + delta, view.center.y);
        }
    };

    // we want to move the labels only if editing is different from the current isEditing state
    if (editing != self.isEditing)
    {
        // execute the move block, animated or not
        if (animated)
            [UIView animateWithDuration:animationDuration animations:moveBlock];
        else
            moveBlock();
    }

    // call the super implementation
    [super setEditing:editing animated:animated];
}
于 2013-05-08T09:41:29.560 に答える
3

すべてのコードをチェックしたわけではありませんが、削除の両側に開始/終了の更新を追加する必要があります...

[self.drinksTableView beginUpdates];
[self.drinksTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.drinksTableView endUpdates];

...アニメーションを取得します。

于 2012-09-07T03:01:15.013 に答える
3

このタスクは、gesturerecognizerを使用して実行できます。セルの管理に役立つ場合があります。また、デフォルトの削除ボタンの代わりに、セルにカスタム削除ボタンを追加することもできます。

于 2013-05-06T13:28:37.653 に答える
2

フレームを設定することにより、tableView:didEndEditingRowAtIndexPath:UILabelを手動で再配置するタスクを実行します

- (void)tableView:(UITableView*)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
    homeCell *cell = (homeCell *)[tableView cellForRowAtIndexpath:indexPath];

    UILabel *labelToBeRelocated = (UILabel *)[cell viewWithTag:YOUR_LABEL_TAG];

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.25f];

    [labelToBeRelocated setFrame:CGRectMake(New_PosX , New_PosY , width , height)];

    [UIView commitAnimations];
}

上記のデリゲートメソッドは、EditingButton(削除ボタン)がUITableViewCellで非表示にされた後に呼び出されるため、UILabelは、削除ボタンが非表示にされた後にのみその位置を再配置します。それがあなたを助けることを願っています。

于 2013-05-06T13:50:30.243 に答える