【问题标题】:Animate 24 large images - each of 728x936 size动画 24 张大图像 - 每张 728x936 尺寸
【发布时间】:2012-03-07 16:45:50
【问题描述】:

我现在通过设置 UIImageView 图层的内容让它们动画化。 我也尝试过设置 UIImageView 的图像属性:

self.curtainAnimationView.image = image;

我正在使用 NSTimer 来调用设置图像的方法:

- (void) performCurtainAnimationWithFrame {    
    NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
    CGImageRef ref = ((UIImage *)[animationImages objectAtIndex:currentFrame]).CGImage;    
    self.curtainAnimationView.layer.contents = (id)ref;
    CGImageRelease(ref);
    [pool drain];

    currentFrame++;
}

定时器功能是:

NSTimer* timer = [NSTimer timerWithTimeInterval:0.1 target:self selector:@selector(performCurtainAnimationWithFrame) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];

这是一个 iPad 项目,因此图像尺寸很大。

我也使用了 UIImageView 的 animationImages 属性,但我需要知道 UIImageView 中没有委托方法的动画何时结束。

如果有人有任何意见,将不胜感激。

【问题讨论】:

    标签: ios ipad animation ios5 timer


    【解决方案1】:

    如何从数组制作动画

    yourImageView.animationImages=arrayOfImages;
    yourImageView.animationDuration=5.0;
    yourImageView.animationRepeatCount=1;
    
    [yourImageView startAnimating];
    

    那你就知道持续时间了

    [self performSelector:@selector(yourMethod) withObject:nil afterDelay:5.0];
    

    【讨论】:

    • 正如我所说,我已经尝试过 UIImageView 的 animationImages 属性。由于图片的大小,不保证动画会在 5 秒后结束,而且我想在 1 秒内完成动画,而且肯定需要更长的时间。
    【解决方案2】:

    这可能看起来有点花哨,但为什么不把它做成视频然后播放呢?播放完毕后,代理会通知您。

    【讨论】:

    • 那是因为我在动画播放完后立即播放视频。我正在使用的动画作为幕开。我已经尝试过播放一个视频,然后播放另一个视频,但在原来的 iPad 上看起来真的很糟糕 - 在动画视频的开头有一个日志,而且视频没有任何透明度。
    • 啊,我明白了,嗯,如果窗帘本身没有波纹或其他动画,您可以在 CALayer 中使用一两个图像并为图层设置动画。如果窗帘在移动,请尝试 CAKeyframeAnimation 并使用 CGIImageRefs 为内容设置动画(保持图层不透明也会有所帮助)。您还可以尝试预先创建一个数组 CALayers(并调用 display),并将预渲染的 CALayer.content 用于 CAKeyframeAnimation 内容动画。
    猜你喜欢
    • 1970-01-01
    • 2011-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-15
    • 1970-01-01
    • 2017-01-20
    • 2017-09-19
    相关资源
    最近更新 更多