简体   繁体   English

如何为UITableView节的页脚设置动画

[英]How to animate UITableView section footer

I am trying to animate a UITableView section footer. 我正在尝试为UITableView节的页脚设置动画。 I have tried the following code: 我尝试了以下代码:

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
CustomView *footer = [[CustomView alloc]initWithFrame:CGRectZero
                                            labelText:@"I am a label in a footer"];
footer.label.alpha = 0.0f;
[UIView animateWithDuration:5.0f
                      delay:0.0f
                    options:UIViewAnimationOptionCurveLinear
                 animations:^{
                     footer.label.alpha = 1.0f;
                 }
                 completion:nil];

return footer;
}

But the footer displays without animation. 但是页脚显示时没有动画。 What's the correct way to animate a UITableView section footer? 为UITableView节页脚设置动画的正确方法是什么? I believe it is possible but can't find an answer for it. 我相信有可能,但找不到答案。

Try doing the animation in the tableView:willDisplayFooterView:forSection: method instead. 尝试在tableView:willDisplayFooterView:forSection:方法中制作动画。 In the method you are using, the view is not inserted into the view hierarchy yet (and thus not in a window), so animations really won't do anything (and they would likely be cancelled by inserting it into a view anyways). 在您使用的方法中,视图尚未插入视图层次结构中(因此不在窗口中),因此动画实际上不会做任何事情(无论如何将其插入视图中都将被取消)。 The -willDisplay* variants are really where you should configure visible UI properties, since it should be in the view hierarchy at that point, and things like UIAppearance values should have been set so your settings won't be overwritten later. -willDisplay *变量确实是您应该在其中配置可见UI属性的位置,因为它那时应该位于视图层次结构中,并且应该设置UIAppearance值之类的东西,以便以后不会被覆盖。

You can often get away with configuring properties in the cellForRowAtIndexPath: method (or viewForFooter in this case) but not always -- and definitely for animations. 您通常可以通过在cellForRowAtIndexPath:方法(在这种情况下为viewForFooter)中配置属性来摆脱困境,但并非总是如此-绝对是动画。

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

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