首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CATransaction insertRowsAtIndexPaths,动画不会结束

CATransaction insertRowsAtIndexPaths,动画不会结束
EN

Stack Overflow用户
提问于 2015-01-26 19:53:01
回答 1查看 375关注 0票数 2

我们的应用程序有一个表视图,允许用户最小化/最大化其节。也有与隐藏/显示行相关的动画,取决于用户的输入,以及连接到不同的设备(通过蓝牙4.0)。由于动画的不同来源,我们设置了一个调度程序来一次处理一个动画,这样就不会有任何崩溃与表视图endUpdates之后的行/节不同步所关联。为了我们的目的,它一直运作得很好。

然而,在我们的桌子上有一个新的部分给我带来了一点悲伤。根据连接到iPad的设备,该部分要么有一行,要么有8-9行。其余行的高度为0。当它有8-9行时,这个部分会最小化/最大化。但是,当节只有一行时,表的insertRowsAtIndexPaths动画直到该节的行离开屏幕时才会完成。因此,除非用户更改选项卡或向下滚动到足以将表从屏幕上推开,否则由于调度程序已经很忙,没有其他部分可以最小化/最大化。下面是为动画调用的代码:

代码语言:javascript
复制
-(void)animateTableUsingAnimationType:(NSNumber*)aniType
{
    static int animationID = -1;
    if(tableAnimationBusy)
    {
        [self performSelector:@selector(animateTableUsingAnimationType:) withObject:aniType afterDelay:.05f];
    }
    else
    {
        tableAnimationBusy = true;
        tat = [aniType intValue];
        [CATransaction begin];
        [CATransaction setCompletionBlock:^{
            NSLog(@"Animation %d is complete!", tat);
            tableAnimationBusy = false;
        }];

        //if-else if blocks checking for the animationID
        //if open section 2
            [self animateOpenTableSection:2]
        else //undefined ID
            tableAnimationBusy = false;

        [CATransaction commit];
        [self setUpLabelText];
    }
}

animateOpenTableSection是:

代码语言:javascript
复制
-(void)animateOpenTableSection:(NSInteger)section
{
    NSLog(@"Calling open on section: %d", section);
    if (section == 2)
    {
        [self.tableView beginUpdates];
        openFlagSettingsRowCount = fsr_COUNT; //max row count for section

        [[MCUISectionHandler sharedInstance] sectionTouched:YES forSection:MCUISH_SECTION_NAME__FLAG];
        NSMutableArray *indexPathsToInsert = [[NSMutableArray alloc] init];
        for (NSInteger i = 0; i < fsr_COUNT; i++) {
            [indexPathsToInsert addObject:[NSIndexPath indexPathForRow:i inSection:section]];
        }
        [self.tableView insertRowsAtIndexPaths:indexPathsToInsert withRowAnimation:UITableViewRowAnimationFade];
        [self.tableView endUpdates];
    }
}

如您所见,我在animateOpenTableSection函数中有调试语句,也有animateTableUsingAnimationType中的完成块。直到单行离开屏幕时,才会调用后者。对于为什么桌面视图不放弃CATransaction,有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-18 22:59:38

我们能够解决这个问题,我忘记张贴我发现的关于我们的应用程序。表视图不放弃CATransaction的原因是行中的UIActivityIndicator子视图。它们被动画化,所以CATransaction从未结束,因为它等待一个或多个UIActivityIndicators停止动画。

因此,对于那些可能遇到这个问题的人,请检查是否有任何子视图被动画化。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28157672

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档