Анимированный GIF не работает на iPhone - PullRequest
7 голосов
/ 10 июня 2009

Я использую cell.image = an animated gif file (ячейка UITableViewCell). Однако это не одушевляет. Есть ли способ, как я могу это исправить?

Ответы [ 5 ]

16 голосов
/ 10 июня 2009

UIImageView предоставляет необходимые API для создания ваших собственных анимаций, таких как:

UIImage *frame1 = [UIImage imageNamed:@"frame1.png"];
UIImage *frame2 = [UIImage imageNamed:@"frame2.png"];
UIImage *frame3 = [UIImage imageNamed:@"frame3.png"];
UIImage *frame4 = [UIImage imageNamed:@"frame4.png"];


UIImageView.animationImages = [[NSArray alloc] initWithObjects:frame1, frame2, frame3, frame4, nil];
UIImageView.animationDuration = 1.0 //defaults is number of animation images * 1/30th of a second
UIImageView.animationRepeatCount = 5; //default is 0, which repeats indefinitely
[UIImageView startAnimating];

//[uiImageView stopAnimating];
2 голосов
/ 10 июня 2009

В iPhone OS 3.0, cell.image больше не поддерживается. Вместо этого ячейки имеют свойство imageView, которое дает вам больше гибкости. Вы можете разделить анимированный GIF-файл на отдельные изображения, а затем сделать это:

anImageView *UIImageView = [[UIImageView alloc] init];
anImageView.animationImages = imagesArray; //this is an array of UIImages you have to create
1 голос
/ 12 января 2016

Пожалуйста, посмотрите следующий код, надеюсь, он будет вам полезен ...

1. Удалить код анимации в cellforatindexpath

2. оживить его, когда отображается ячейка

3. остановить анимацию, скрывая ячейки

4. Улучшит производительность приложения

5. Экономьте больше памяти

    -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    NSArray *myImageArray = [NSArray arrayWithObjects:
                             [UIImage imageNamed:@"image1.png"],
                             [UIImage imageNamed:@"image2.png"],
                             [UIImage imageNamed:@"image3.png"],
                             [UIImage imageNamed:@"image4.png"],
                             [UIImage imageNamed:@"image5.png"],nil];

    [cell.imageView setAnimationImages:myImageArray];
    cell.imageView.animationDuration = 4.0;
    cell.imageView.animationRepeatCount = 1;
    [cell.imageView startAnimating];
    }

     -(void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    [cell.imageView stopAnimating];
    [cell.layer removeAllAnimations];
    }  
1 голос
/ 05 января 2010

Только UIWebView поддерживает отображение анимированного GIF-файла.

0 голосов
/ 10 июня 2009

Вы можете только написать собственный механизм рендеринга GIF-файла в представлении или подождать, пока Apple его исправит.

...