2
我想爲單元格添加無限變色動畫。上述代碼無法正常工作。它在一點毛刺(0.3秒左右)後開始用alpha(不是我先設置的顏色)進行動畫處理。UITableViewCell背景色動畫
- (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
細胞和動畫,然後一切工作正常,除了隔膜沒有動畫。
我已經試過了。沒有幫助。 – user1561346
我編輯了一個爲我工作的例子。如果它仍然不適合你,請上傳你的代碼,並描述會發生什麼(可能問題根本與此無關) –
謝謝。是的,它工作,如果表剛剛加載。嘗試將'indexPath.row == 5'更改爲'[indexPath isEqual:_animatingCellIndexPath]'並添加此代碼wor animation start:' - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [ tableView deselectRowAtIndexPath:indexPath animated:false]; _animatingCellIndexPath = indexPath; [tableView reloadRowsAtIndexPaths:@ [_ animatingCellIndexPath] }' – user1561346