【发布时间】:2015-07-20 07:39:50
【问题描述】:
我想为单元格添加无限变色动画。上面的代码不能正常工作。在出现小故障(0.3 秒左右)后,它开始从带有 alpha 的颜色(不是从我首先设置的颜色)开始动画。
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:@"SuggestionCell"];
if ([indexPath isEqual:_animatingCellIndexPath]) {
cell.backgroundColor = [UIColor redColor];
[UIView animateWithDuration:0.5 delay:0.0
options:UIViewAnimationOptionAutoreverse
| UIViewAnimationOptionRepeat
| UIViewAnimationOptionAllowUserInteraction
animations:^{
cell.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.4];
}
completion:NULL];
}
else {
cell.backgroundColor = [UIColor whiteColor];
}
}
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:false];
_animatingCellIndexPath = indexPath;
[tableView reloadRowsAtIndexPaths:@[_animatingCellIndexPath] withRowAnimation:UITableViewRowAnimationNone];
}
可以为单元格设置backgroundView 并为其设置动画,然后一切正常,除了分隔符没有动画。
【问题讨论】:
标签: ios objective-c uitableview uiview uiviewanimation