我正在开发一个 iOS 应用程序,该应用程序在一个视图中具有UITableView
有两个定制UITableViewCell
。所有这些都使用主故事板。
一切都很好。但我需要实现的是一个单一的淡入/淡出动画UIView
from just one cell.
目前我正在使用此代码来为视图设置动画:
[UIView animateWithDuration:1.2
delay:0
options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveEaseInOut animations:^{
self.myView.alpha = 0;
} completion:^(BOOL finished) {
self.myView.alpha = 1;
}];
在我调用的“设置内容”方法中tableView:cellForRowAtIndexPath:
数据源方法UITableView
.
动画效果正常。即使视图之间发生变化,视图仍然具有动画效果。我的问题是,当我从表视图重新加载数据时,或者表视图向上或向下滚动,直到带有动画的单元格消失,并且必须重新使用该单元格才能再次显示它,此时单元格没有动画呈现。
我在这里缺少什么?有没有更好的方法来实现这个?表视图重用单元格后如何重新启动动画?
我认为重要的是要指出的是,根据我的 UI 设计,只有一个单元格才会有动画。
Thanks.
我认为你应该再实施一项delegate
的方法UITableView
,即 -
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
& 在其中相应单元格的相应视图上执行动画。
每次显示单元格时都会调用下面的方法(如果它超出 TableView 的框架并返回到可见区域)
-(void) tableView:(UITableView *) tableView willDisplayCell:(UITableViewCell *) cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
//row number on which you want to animate your view
//row number could be either 0 or 1 as you are creating two cells
//suppose you want to animate view on cell at 0 index
if(indexPath.row == 0) //check for the 0th index cell
{
// access the view which you want to animate from it's tag
UIView *myView = [cell.contentView viewWithTag:MY_VIEW_TAG];
// apply animation on the accessed view
[UIView animateWithDuration:1.2
delay:0
options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveEaseInOut animations:^
{
[myView setAlpha:0.0];
} completion:^(BOOL finished)
{
[myView setAlpha:1.0];
}];
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)