Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
628 views
in Technique[技术] by (71.8m points)

iphone - Callback for UITableView animations

Is there a delegate protocol that includes a callback for the end of animated changes to UITableView? Particularly reloadSection/Rows?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Actually, there DOES seem to be a way to do this (though not nearly as straightforward as it ought to be!).

While there's no direct access to some kind of callback, it appears that UITableView animations take place within a CAAnimation. Therefore, simply accessing the completionBlock of the CAAnimation seems to give you what you want.

Here's how I got 2 animations to chain in my UITableView subclass:

#pragma mark - Section expanding/collapsing
- (void)toggleSection:(NSInteger)index {
    int expandedSection = [self ExpandedSection];
    if (expandedSection != NO_EXPANDED_SECTIONS_INDEX) {
        [self beginUpdates];
        [self collapseSection:@(expandedSection)];
        [CATransaction setCompletionBlock:^{
            if (expandedSection != index) {
                [self beginUpdates];
                [self expandSection:@(index)];
                [self endUpdates];
            }
        }];
        [self endUpdates];
    } else {
        [self expandSection:@(index)];
    }
}

The code in the collapseSection: and expandingSection: methods simply adds/removes sub-sections that need to be collapsed or expanded. The key point here, though, is that, when using this code, I am finally able to collapse one sub-section THEN expand the next sub-section. Before, both animations were occurring concurrently, which was visually unappealing.

I hope this helps you! I struggled through this for a long time, banging my head against the wall until I found this.

This is written against iOS 6.0. I also really hope that some future version makes this workaround/hack obsolete!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...