UITableViewCell中的UIViewanimation
我正在开发一个iOS应用程序,在一个视图中具有两个自定义UITableViewCell
。 所有这些使用主要的故事板。
一切工作都很好。 但是我需要实现的是从一个单元格在一个UIView
单个淡入/淡出animation。
目前我正在使用这个代码来animation视图:
[UIView animateWithDuration:1.2 delay:0 options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveEaseInOut animations:^{ self.myView.alpha = 0; } completion:^(BOOL finished) { self.myView.alpha = 1; }];
在我调用UITableView
的tableView:cellForRowAtIndexPath:
数据源方法的“set content”方法中。
animation工作正常。 即使观点之间的变化仍然animation视图。 我的问题是,当我重新加载数据从表视图或表视图向上或向下滚动,直到与animation的单元格消失,它必须重用该单元格再次显示,在那一刻的单元格提交没有animation。
我在这里错过了什么? 有没有更好的方法来实现这一点? 表格视图重用单元格后,如何重新启动animation?
我认为重要的是要说,根据我的UIdevise,只有一个单元格将有animation。
谢谢。
我想你应该实现一个更多的UITableView
delegate
方法,
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
并在其中的相应单元格的相应视图上执行animation。
每次显示单元格时都会调用下面的方法(如果它离开了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]; }]; } }