我有一个使用相机的应用程序,上面覆盖了枪支图像以及开火和重新加载按钮。在视网膜版 iPad 和 iPhone 上,开火动画在大约一秒内循环播放 30 张图像,在装填动画则在 2 秒内循环播放 41 张图像。所有图像都是 1920 x 1080,在 iPhone 上它们是 1000 x 533。例如,要在点击点火按钮时循环浏览 .png,我在 PlayViewController.m 文件中使用它:
- (IBAction)fire:(id)sender {
// Play the firing animation for the rifle, enable reload button
fireButton.enabled = NO;
type.animationImages = gunanimload;
type.animationDuration = 1.0;
type.animationRepeatCount = 1;
reloadButton.enabled = YES;
[type startAnimating];
在 viewDidLoad 方法中,我创建数组并加载图像:
- (void)viewDidLoad
{
[super viewDidLoad];
UIImage* img1 = [UIImage imageNamed:@"rev0001.png"];
... x30
gunanimload = [NSArray arrayWithObjects:img1, ... x30, nil];
}
尽管它应该在 View 加载时加载数组,但当点击 Fire 按钮时它似乎仍然在加载数组。我该如何消除这种延迟?或者是否有(相对简单的)替代播放开火和重新加载动画的方法?
最佳答案
UIImage imageNamed 方法在需要显示图像之前不会加载图像。有一些方法可以预先预加载图像。
阅读此内容以获取更多信息: CGImage/UIImage lazily loading on UI thread causes stutter
关于iphone - 播放png动画时出现延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12262652/