简体   繁体   English

在UITableView中对单元格进行动画处理

[英]Animating cells in UITableView

I have a section in UITableView that once I click on it 4 animated cells drop down, however, the problem is that when they drop down they go down past the view (screen), and you can't see them unless you scroll down. 我在UITableView中有一个部分,一旦单击它,就会放下4个动画单元格,但是问题是,当它们下拉时,它们会滑过视图(屏幕),除非向下滚动,否则您将看不到它们。 How would I make it so that once the section is clicked that it push the entire view up revealing all the cells in the drop down menu? 我将如何做到这一点,一旦单击该部分,它将向上推动整个视图以显示下拉菜单中的所有单元格? Here's my code: 这是我的代码:

- (void) sectionOpened : (NSInteger) section{

    SectionInfo *array = [self.sectionInfoArray objectAtIndex:section];
    array.open = YES;

    NSInteger count = [array.category.list count];
    NSMutableArray *indexPathToInsert = [[NSMutableArray alloc] init];
    for (NSInteger i = 0; i<count;i++)
    {
        [indexPathToInsert addObject:[NSIndexPath indexPathForRow:i inSection:section]];
    }

    NSMutableArray *indexPathsToDelete = [[NSMutableArray alloc] init];
    NSInteger previousOpenIndex = self.openSectionIndex;
    if (previousOpenIndex != NSNotFound)
    {
        SectionInfo *sectionArray = [self.sectionInfoArray objectAtIndex:previousOpenIndex];
        sectionArray.open = NO;
        NSInteger counts = [sectionArray.category.list count];
        [sectionArray.sectionView toggleButtonPressed:FALSE];
        for (NSInteger i = 0; i<counts; i++)
        {
            [indexPathsToDelete addObject:[NSIndexPath indexPathForRow:i inSection:previousOpenIndex]];
        }
    }
    UITableViewRowAnimation insertAnimation;
    UITableViewRowAnimation deleteAnimation;
    if (previousOpenIndex == NSNotFound || section < previousOpenIndex)
    {
        insertAnimation = UITableViewRowAnimationTop;
        deleteAnimation = UITableViewRowAnimationBottom;
    }
    else
    {
        insertAnimation = UITableViewRowAnimationBottom;
        deleteAnimation = UITableViewRowAnimationTop;
    }

    [atableView beginUpdates];

    [atableView insertRowsAtIndexPaths:indexPathToInsert withRowAnimation:UITableViewRowAnimationTop];
    [atableView deleteRowsAtIndexPaths:indexPathsToDelete withRowAnimation:deleteAnimation];


    [atableView endUpdates];

    self.openSectionIndex = section;

} 

Any Ideas? 有任何想法吗?

Have you tried using this tableView method? 您是否尝试过使用此tableView方法?

- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated

So you could try. 所以您可以尝试。

[atableView scrollToRowAtIndexPath:indexPathToInsert atScrollPosition: UITableViewScrollPositionTop animated:YES];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM