1

私は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]実行時に終了する必要があることです。したがって、アコーディオンは完璧に実行されます。助けてくれてありがとう..

4

2 に答える 2

1

ビュープロパティ (スクロール ビューのフレーム) を変更しているので、UIView アニメーションを使用してフレームをアニメーション化することをお勧めします。完璧に見えるようにタイミングを微調整する必要があるかもしれませんが、アニメーションは EaseInEaseOut であり、0.4 秒かかると思います。次のようなアニメーションを作成します。

[UIView animateWithDuration:0.4 animations:^{
    // Change all your animatable properties like your frames here...
    yourScrollView.frame = theNewScrollViewFrame;
}];
于 2012-06-04T13:47:26.093 に答える
1

最終的に次のコードで修正しました

// Start the animation before the begin update and commit it after the end update.        
[UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.3];

        [tableView beginUpdates];
<My code which I given in the question>
       [tableView endUpdates];
        [UIView commitAnimations];

それが将来誰かに役立つことを願っています..

于 2012-06-08T10:36:37.477 に答える