iphone - 播放png动画时出现延迟

标签 iphone objective-c ios xcode ipad

我有一个使用相机的应用程序,上面覆盖了枪支图像以及开火和重新加载按钮。在视网膜版 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

Non-lazy image loading in iOS

关于iphone - 播放png动画时出现延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12262652/

相关文章:

iphone - 在 iOS5 中检测静音模式?

iphone - 如何在 GLPaint 示例代码中创建自己的 recordedPath

IOS - 从 Ipod 访问音频流、暂停和更改音量

ios - 呈现 UIAlertController 时出现 CGContext 错误

iOS - 如何填充 UIPickerView?

iphone - 来自 View Controller 类中的某个类调用方法

iphone - 如何从核心数据库获取数据

objective-c - EXC_BAD_ACCESS 尝试读取 NSArray

iphone - 在网络上找不到 iOS/Mac Bonjour 服务

ios - 未调用单元测试 Storyboard viewDidLoad