2011-07-20 48 views
0

我有点卡住这个问题。我有一个带有37张图像的UIImageView动画,其中展示了一个装满酒精的玻璃杯。 我初始化我的图像阵列中的viewDidLoad,UIImageView animateImages延迟

NSArray * GlassAnim = [[NSArray alloc] initWithObjects: 
         [UIImage imageWithContentsOfFile: 
[[NSBundle mainBundle] pathForResource:@"SodaPour1" ofType:@"png"]], 
         [UIImage imageWithContentsOfFile: 
[[NSBundle mainBundle] pathForResource:@"SodaPour39" ofType:@"png"]], 
         nil]; 

imgGlass.animationImages = GlassAnim; 
imgGlass.animationDuration = 2.5; 
imgGlass.contentMode = UIViewContentModeScaleAspectFit; 
imgGlass.animationRepeatCount=1; 
[GlassAnim release]; 

然后我打电话startAnimating当用户点击屏幕。但问题是动画第一次延迟了半秒。每个图片的尺寸为330 * 372像素,文件大小为180KB png文件。除了播放视频之外,还有更好的方法吗?

谢谢。

+0

一个提示。你可以使用较短的形式为UIImage:'[UIImage imageNamed:@“SodaPour18.png”]' – Cyprian

+0

没有可观的变化。有没有办法使用CALayer动画来做这件事?... –

+0

Mods不会根据用户的请求回答问题,因此标记主持人的注意力不会奏效。如果你想为你的问题留下一些注意,我会高度建议你1)[编辑](http://stackoverflow.com/posts/6762408/edit)你的问题,使你的代码适合而不会导致滚动条出现(你*认真*不需要所有那些该死的UIIMage线;削减其中的大部分,缩短剩下的并将它们移动到左边),然后2)对您的问题进行奖励。你可以在[faq#bounty]中阅读赏金。祝你好运。 – Will

回答

0

在这里你去,

  1. 就启动了一个定时器来改变形象的名字。

    timerAnimation = [[NSTimer scheduledTimerWithTimeInterval:0.10 target:self 
    selector:@selector(changeImagesAccordingly) userInfo:nil repeats:YES] 
    retain]; 
    
  2. 重命名序列中的图像。我有16张图片。

    如: - “AnimationImg1.png”, “AnimationImg2.png”, “AnimationImg3.png”

    - (void)changeImagesAccordingly { 
        if (iImgAnim<16) { 
         imgView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] 
           pathForResource:[NSString stringWithFormat:@"AnimationImg%d",iImgAnim] ofType:@"png"]]; 
         iImgAnim++; 
        } else { 
         [timerAnimation invalidate]; 
         iImgAnim=1; 
        } 
    } 
    

应该这样做:)

+1

这个答案是一个好的第一步,因为它不会在动画之前将所有图像解码到内存中。你可能仍然会遇到一些性能问题,因为它看起来像是在用相当大的图像来获得大约20FPS的图像。有关FPS和性能的更多信息,请参阅http://stackoverflow.com/questions/16880798/how-to-assemble-animation-from-an-array-of-images-with-the-highest-fps-possible/17128678 #17128678 – MoDJ

+0

感谢您的提示MoDJ。在我的情况下,我能够解决它。但你的答案应该是我猜的正确答案。 –

+0

你的方法足以作为第一枪。请注意,你可以在这个答案中找到我自己的同类型的基于计时器的impl http://stackoverflow.com/questions/442076/method-for-animating-images-like-a-movie-on-iphone-without - 使用 - mpmovieplayer/6077394#6077394 – MoDJ