テーブルビューのヘッダー/フッター コンテンツの削除をアニメーションでアニメーション化するのに苦労しています。ヘッダーの内容自体でremoveFromSuperviewを呼び出すか、ヘッダーをnilに割り当てるだけでよいと思いますが、これをアニメーション化する方法がわかりません。単純なアニメーション ブロックでは何もできません。ビュー (この場合はラベル) をフェード イン/アウトするにはどうすればよいですか?
7 に答える
アニメーション ブロックを使用してヘッダー ビューを完全に削除する方法の例を書きました。
[UIView beginAnimations:nil context:NULL];
[self.tableView setTableHeaderView:nil];
[UIView commitAnimations];
もちろん、これは、このアニメーションが UITableViewController クラス内で呼び出されていることを前提としています。
スーパービューからヘッダー ビューを削除するだけでは機能しません。テーブル ビューは、以前のヘッダー ビューを埋めるためにサイズを変更する方法を認識していないためです。ヘッダー ビューの設定により、テーブル ビューがアニメーションで更新されます。
これが機能しない場合は、tableView インスタンスの割り当てを確認してください。
私は次の簡単な解決策になりました。ヘッダーの削除をアニメーション化します。
[self.tableView beginUpdates];
self.tableView.tableHeaderView = nil;
[self.tableView endUpdates];
これは WINSergey の回答で言及されていることは承知していますが、彼の説明は少しわかりにくいと感じました。
次の2つのオプションが両方とも正常に機能することがわかりました。
オプション1
[UIView animateWithDuration:0.15
delay:0.0
options: UIViewAnimationCurveEaseOut
animations:^{deleteLabel.alpha = 0;}
completion:nil];
オプション 2
[UIView beginAnimations:nil context:nil];
deleteLabel.alpha = 0.0;
[UIView commitAnimations];
私は同じ問題を抱えていました。ヘッダーの削除方法を制御したかったのですが、ここに私の方法があります:
ViewDidLoad で:
UIView *transView = [[UIView alloc] initWithFrame:CGRectMake(0.f, 0.f, 320.f, 200.f)];
transView.backgroundColor = [UIColor clearColor];
self.headerView = transView;
[transView release];
[self.tableView setTableHeaderView:self.headerView];
次に、ヘッダーを削除する必要がある場合:
[UIView animateWithDuration:.3f
delay:.0f
options: UIViewAnimationOptionBeginFromCurrentState
animations:^{
self.headerView.frame = CGRectMake(0.0f, 0.0f, 320.f, 0.0f);
}
completion:^(BOOL finished) {
[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:section] atScrollPosition:UITableViewScrollPositionTop animated:YES];
}];
これは「そのまま」完全に機能し、アニメーションは気にしません
[myPrettyViewControllerInstance letUpdatePrettyViewNow];
[[self tableView] beginUpdates];
[[self tableView] setTableHeaderView:[myPrettyViewControllerInstance view]];
[[self tableView] endUpdates];
しかし、それ以上必要ない場合
[[self tableView] setTableHeaderView:nil];
本当に必要なのはこれだけです(フェードアウトでない場合は、
[[self tableView] setTableHeaderView:nil];
そして、私たちは必要ありません
[UIView beginAnimations:nil context:NULL];
[[self tableView] setTableHeaderView:nil];
[UIView commitAnimations];
いいえ
[[self tableView] beginUpdates];
[[self tableView] setTableHeaderView:nil];
[[self tableView] endUpdates];
いいえ
[[self tableView] setTableHeaderView:nil];
[[self tableView] reloadData];
いや..
それを機能させるには、2つのアニメーションを配置する必要がありました。
[UIView animateWithDuration:2.0f animations:^{
mylbl.alpha = 0.1 ;
} completion:^(BOOL finished) {
[UIView animateWithDuration:2.0f animations:^{
mylbl.alpha = 1.0 ;
}];
}];