我试图在UITableView
页脚视图中为一个微妙的跳动警告标签制作动画,但由于某种原因,我的动画不是,好......动画。奇怪的是动画的效果(即最终结果)正在生效,但它既不是动画也不是循环。它只是立即出现在最终状态,好像它根本不在动画块中。
这是我想要应用的动画:
- (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;
}
答案 0 :(得分:0)
尝试将动画块移动到tableView:didEndDisplayingFooterView:forSection:
方法。不要直接在那里制作动画,只需返回一个视图。
答案 1 :(得分:0)
我将动画调用包裹在dispatch_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];
});