Я пытаюсь отобразить анимированный UIImage в imageView UITableViewCell. Анимационное изображение отображается после первого присваивания, но не при каждой последующей попытке.UIImageView в UITableViewCell не анимируется, когда анимированный UIImage назначается дважды
Вот код TableViewController:
#import "ViewController.h"
@interface ViewController()
@property (nonatomic, strong) UIImage *animatedImage;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.animatedImage = [UIImage animatedImageNamed:@"syncing" duration:1.0];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static BOOL second = NO;
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (second) {
cell.imageView.image = nil;
NSLog(@"Removed image");
}
else {
cell.imageView.image = self.animatedImage;
NSLog(@"Added image");
if (![cell.imageView isAnimating]) {
[cell.imageView startAnimating];
NSLog(@"Started animation for UIImageView: %@", cell.imageView);
}
}
second = !second;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
@end
И это выход, когда я нажимаю Клетка два раза:
Added image
Started animation for UIImageView: <UIImageView: 0x7197540; frame = (0 0; 0 0); opaque = NO; userInteractionEnabled = NO; animations = { UIImageAnimation=<CAKeyframeAnimation: 0x715bc80>; }; layer = <CALayer: 0x71975a0>> - (null)
Removed image
Added image
Started animation for UIImageView: <UIImageView: 0x7197540; frame = (6 6; 30 30); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x71975a0>> - (null)
Проверьте эту тему http://stackoverflow.com/questions/4001043/why-does-my-animation-in-my-cell-disappear-when-the-cell-is-selected/33021637#33021637 Это помогло мне с аналогичной проблемой. –
Я отправил ответ здесь. Plz check: http://stackoverflow.com/a/34741997/4720315 –