をスクロールしたとき、私はそうのように、各行の左にあるチェックボックスを表示するためにlayoutSubviewsでアニメーションを開始するカスタムのUITableViewCellを作成する必要がどの愛のexample for Multi-row selectionとココアを実装しました:UITableViewCellのアニメーション
- (void)layoutSubviews
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[super layoutSubviews];
if (((UITableView *)self.superview).isEditing)
{
CGRect contentFrame = self.contentView.frame;
contentFrame.origin.x = EDITING_HORIZONTAL_OFFSET;
self.contentView.frame = contentFrame;
}
else
{
CGRect contentFrame = self.contentView.frame;
contentFrame.origin.x = 0;
self.contentView.frame = contentFrame;
}
[UIView commitAnimations];
}
これは正常に動作しますすべての目的と目的のために、私のUITableViewは必要に応じて動作します。しかし、私は小さな審美的な問題に直面しています。以前に表示されていないUITableViewの行をスクロールすると、スライディングアニメーションが開始されます。
これは、setAnimationBeginsFromCurrentStateがYESに設定されていて、UITableViewのさらに下の行がまだフレーム位置が更新されていないことを前提として、わかります。この問題を解決するために、私はwillDisplayCellを使用して、UITableViewが編集モードのときに表示されるセルのアニメーションをオーバーライドしようとしました。基本的にアニメーションをバイパスして、細胞がまだのように、所定の場所にアニメーションしているかのように表示させるように、すぐに行フレームの更新:
/*
Since we animate the editing transitions, we need to ensure that all animations are cancelled
when a cell is scheduled to appear, so that things happen instantly.
*/
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
[cell.contentView.layer removeAllAnimations];
if(tableView.isEditing) {
CGRect contentFrame = cell.contentView.frame;
contentFrame.origin.x = EDITING_HORIZONTAL_OFFSET;
cell.contentView.frame = contentFrame;
} else {
CGRect contentFrame = cell.contentView.frame;
contentFrame.origin.x = 0;
cell.contentView.frame = contentFrame;
}
}
残念ながら、これはどんな効果を持っていないようです。どのように私はこの問題を解決することができるように誰もが考えを持っていますか?