【问题标题】:How to startAnimating the .gif every cell in the tableView?如何开始为 tableView 中的每个单元格设置 .gif 动画?
【发布时间】:2011-10-27 02:38:37
【问题描述】:

当我在 tableview 中选择一个单元格时,.gif 的动画会停止。怎么解决,谁能给点建议?

【问题讨论】:

    标签: iphone objective-c ios tableview gif


    【解决方案1】:

    iOS 不支持gif 动画。你必须这样做 -

    -(void)startImageViewAnimation
    {
    NSArray *animationImages = [NSarray arrayWithObjects:[UIImage imageNamed:@"1.png"],
    [UIImage imageNamed:@"2.png"],
    [UIImage imageNamed:@"3.png"],nil];
    
    UIImageView *imageView = [UIImageView alloc] initWithFrame:CGRectMake(0,0,320,480)];
    imageView.animationImages = animationImages ;
    imageView.animationRepeatCount = 2;
    imageView.animationDuration= 4.0;
    [imageView startAnimating];
    
    [NSTimer scheduledTimerWithTimeInterval:4.0 target:self
    selector:@Selector(animationDone:)
    userInfo:nil repeats:NO];
    } 
    
    -(void)animationDone:(NSTimer*)inTimer
    {
    [inTimer invalidate];
    inTimer = nil;
    NSLog(@"animationDone ");
    }
    

    【讨论】:

    • 谢谢,我必须在每个单元格中取ImageViewAnimation,也就是说我必须同时构建这么多NSTimer?
    【解决方案2】:

    据我所知 iPhone SDK 不做 .gifs 你必须通过 UIView 自己做动画

    【讨论】:

      【解决方案3】:

      UIImage 没有对动画 GIF 的内置支持,但使用 Image I/O 框架来加载它们非常容易。

      Image I/O Programming Guide
      Image I/O Reference Collection

      我有从 github 上的动画 GIF 创建动画 UIImage 的示例代码:

      https://github.com/mayoff/uiimage-from-animated-gif

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-12-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-11-03
        • 1970-01-01
        相关资源
        最近更新 更多