gpt4 book ai didi

iphone - UITableView 动画的回调

转载 作者:行者123 更新时间:2023-12-03 19:12:44 25 4
gpt4 key购买 nike

是否有包含 UITableView 动画更改结束回调的委托(delegate)协议(protocol)?特别是 reloadSection/Rows?

最佳答案

实际上,确实似乎有一种方法可以做到这一点(尽管并不像应有的那么简单!)。

虽然无法直接访问某种回调,但 UITableView 动画似乎发生在 CAAnimation 内。因此,只需访问 CAAnimationcompletionBlock 似乎就能满足您的需求。

以下是我在 UITableView 子类中链接 2 个动画的方法:

#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)];
}
}

collapseSection:expandingSection: 方法中的代码只是添加/删除需要折叠或展开的子部分。不过,这里的关键点是,当使用此代码时,我终于能够折叠一个子部分然后展开下一个子部分。之前,两个动画同时发生,这在视觉上没有吸引力。

希望这对您有帮助!我在这个问题上挣扎了很长时间,把头撞在墙上,直到我找到了这个。

这是针对 iOS 6.0 编写的。我也真心希望 future 的版本能让这个解决方法/黑客变得过时!

关于iphone - UITableView 动画的回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2802146/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com