私はUITableView
スクロールビューの中にいます。だから私はを使用してコンポーネントのようなアコーディオンをやろうとしていますUITableView
。したがって、UITableView
セルを追加するには、を拡張する必要があります。UIScrollView
その場合、テーブル アニメーションと一致するように、アニメーションで高さを大きくする必要があります。
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger row = [indexPath row];
BOOL preventReopen = NO;
if (row == expandedRowIndex + 1 && expandedRowIndex != -1)
return nil;
[tableView beginUpdates];
if (expandedRowIndex != -1)
{
familyTableView.frame = CGRectMake(familyTableView.frame.origin.x, familyTableView.frame.origin.y, familyTableView.frame.size.width, 3*50+22);
toolsTableView.frame = CGRectMake(toolsTableView.frame.origin.x, familyTableView.frame.origin.y + familyTableView.frame.size.height + 20, toolsTableView.frame.size.width, 4*50+22);
myAccountTableView.frame = CGRectMake(myAccountTableView.frame.origin.x, toolsTableView.frame.origin.y + toolsTableView.frame.size.height + 20, myAccountTableView.frame.size.width, 2*50+22);
settingsScrollView.contentSize = CGSizeMake(320, familyTableView.frame.size.height + toolsTableView.frame.size.height+ myAccountTableView.frame.size.height + 380);
settingsScrollView.contentInset = UIEdgeInsetsMake(0, 0, familyTableView.frame.size.height + toolsTableView.frame.size.height+ myAccountTableView.frame.size.height + 380, 0);
NSInteger rowToRemove = expandedRowIndex + 1;
preventReopen = row == expandedRowIndex;
if (row > expandedRowIndex)
row--;
expandedRowIndex = -1;
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:rowToRemove inSection:0]] withRowAnimation:UITableViewRowAnimationTop];
}else {
familyTableView.frame = CGRectMake(familyTableView.frame.origin.x, familyTableView.frame.origin.y, familyTableView.frame.size.width, (3*50+22) + 100);
toolsTableView.frame = CGRectMake(toolsTableView.frame.origin.x, familyTableView.frame.origin.y + familyTableView.frame.size.height + 20, toolsTableView.frame.size.width, 4*50+22);
myAccountTableView.frame = CGRectMake(myAccountTableView.frame.origin.x, toolsTableView.frame.origin.y + toolsTableView.frame.size.height + 20, myAccountTableView.frame.size.width, 2*50+22);
settingsScrollView.contentSize = CGSizeMake(320, familyTableView.frame.size.height + toolsTableView.frame.size.height+ myAccountTableView.frame.size.height + 380);
settingsScrollView.contentInset = UIEdgeInsetsMake(0, 0, familyTableView.frame.size.height + toolsTableView.frame.size.height+ myAccountTableView.frame.size.height + 380, 0);
}
NSInteger rowToAdd = -1;
if (!preventReopen)
{
rowToAdd = row + 1;
expandedRowIndex = row;
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:rowToAdd inSection:0]] withRowAnimation:UITableViewRowAnimationTop];
}
[tableView endUpdates];
return nil;
}
私はアニメーションが苦手です。どんな助けでも大歓迎です。私が必要とするのは[tableView beginUpdates]
、UIScrollView へのサイズ変更効果のアニメーション化を開始する必要があり、[tableView endUpdates]
実行時に終了する必要があることです。したがって、アコーディオンは完璧に実行されます。助けてくれてありがとう..