Ios 在UITableView节页脚中设置UILabel alpha动画时出现问题

Ios 在UITableView节页脚中设置UILabel alpha动画时出现问题,ios,objective-c,uitableview,animation,Ios,Objective C,Uitableview,Animation,我试图在UITableViewfooterView中设置一个微妙跳动的警告标签的动画,但由于某些原因,我的动画不是,嗯。。。动画制作。奇怪的是,动画的效果(即最终结果)正在生效,但它既不是动画也不是循环。它只是在最终状态下立即出现,就好像它根本不在动画块中一样 以下是我尝试应用的动画: - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { UIView* vie

我试图在
UITableView
footerView中设置一个微妙跳动的警告标签的动画,但由于某些原因,我的动画不是,嗯。。。动画制作。奇怪的是,动画的效果(即最终结果)正在生效,但它既不是动画也不是循环。它只是在最终状态下立即出现,就好像它根本不在动画块中一样

以下是我尝试应用的动画:

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView* view = [[UIView alloc] initWithFrame:CGRectMake(0,0,tableView.width, kModPopFooterHeight)];
    view.backgroundColor = [UIColor clearColor];
    view.opaque = NO;

    __block UILabel* incompleteLabel = [[UILabel alloc] initWithFrame:view.bounds];
    incompleteLabel.height = kModPopFooterHeight - 8.0;
    incompleteLabel.textAlignment = NSTextAlignmentCenter;
    incompleteLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    incompleteLabel.textColor = [UIColor whiteColor];
    incompleteLabel.font = [UIFont boldSystemFontOfSize:15.0];
    incompleteLabel.text = @"Please complete the above section";
    [view addSubview:incompleteLabel];

    [UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction animations:^{
        incompleteLabel.alpha = 0.1;
    } completion:nil];

    return view;
}

尝试将动画块移动到
tableView:DiEndDisplayingFooterView:forSection:
方法。不要直接在那里设置动画,只返回一个视图。

我将动画调用包装在
dispatch\u async
中,现在它神奇地工作了

dispatch_async(dispatch_get_main_queue(), ^{
    [UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction animations:^{
        incompleteLabel.alpha = 0.1;
    } completion:nil];
});

不走运。但我不认为这是我想要的。根据文档:“告诉代理指定的页脚视图已从表中删除。”。确定。你能试试willDisplay吗?现在就试试,但由于某种原因没有调用它。看起来在使用自定义页脚视图时没有调用
willDisplayFooterView
,将
ViewForFooterInstitution
作为我可以附加动画的唯一点。如果为页脚视图创建自定义类,它也可以工作,并将动画代码放入didMoveToSuperview中;不知道为什么会这样,或者是你的方法导致它工作。可能是时间问题?我猜这与代码执行时已经出现动画有关,但这只是猜测。我做了一些测试,我认为原因实际上是动画开始时标签不在视图层次结构中。如果创建标签,启动动画,然后将标签添加到其superview(使用performSelector:withObject:afterDelay:延迟为0),我会看到与您相同的问题。如果在开始动画之前将标签添加为子视图,它会工作(或者即使在动画代码之后添加标签,但在同一方法中,因此视图似乎必须位于运行循环的同一圈内的视图层次结构中,动画才能工作)。@rdelmar这实际上很有意义。谢谢你的调查!