次のように、layoutSubviews でアニメーションを開始して各行の左側にチェックボックスを表示するカスタム UITableViewCell を作成することを含む、複数行選択の Love の例を使用して Cocoa を実装しました。
- (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;
}
}
残念ながら、これは何の効果もないようです。この問題をどのように解決できるかについて誰か考えがありますか?