HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iphone – 我应该如何在iOS中动画200多张图片?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有超过200张图像,我想在大约10秒的空间内制作动画.我尝试通过将图像加载到数组中然后调用startAnimating方法来使用animation Images.这在模拟器中运行正常但是撞毁了iPad.

我曾尝试每隔1/25秒调用一次NStimer,并在每次定时器触发时更改图像.这比以前的方法表现更好,它在模拟器中运行良好,但在iPad的(滞后)动画结束时也崩溃了.

有人可以帮助我,告诉我解决这个问题的理想方法吗?谢谢.

原始代码

- (void) humptyFallingAnim {

    NSString *filename;
    if (humptyImageCounter < 285) {
        filename = [NSString stringWithFormat:@"Humpty Animation HD1.2 png sequence/humpty_HD1.2_%d.png",humptyImageCounter];
            UIImage *someImage = [UIImage imageNamed:filename];
            humptyFalling.image = someImage;
            NSLog(@"loaded image: %d",humptyImageCounter);
        humptyImageCounter++;
    } else {
        NSLog(@"Timer invalidated");
        [humptyTimer invalidate];
        humptyTimer = nil;
    }

}

编辑:一些不适合我的新代码

NSString *filename;
    if (humptyImageCounter < 285) {
        filename = [NSString stringWithFormat:@"Humpty Animation HD1.2 png sequence/humpty_HD1.2_%d.png",humptyImageCounter];
        @autoreleasepool {
            UIImage *someImage = [UIImage imageWithContentsOfFile:filename];
            humptyFalling.image = someImage;
            NSLog(@"loaded image: %d",humptyImageCounter);
        }
        humptyImageCounter++;
    } else {
        NSLog(@"Timer invalidated");
        [humptyTimer invalidate];
        humptyTimer = nil;
    }

编辑2:

-(void) motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    NSLog(@"You shook it!");
    [self.view bringSubviewToFront:imgSnail];
    if (deviceHasBeenShaken == 0) {
        deviceHasBeenShaken = 1;
    }
    humptyTimer = [NSTimer scheduledTimerWithTimeInterval:(1/25) target:self selector:@selector(humptyFallingAnim) userInfo:nil repeats:YES];
    [self moveHumptyPosition];

}

解决方法

不幸的是,这听起来像OpenGL ES的工作.应用程序是游戏吗?

大佬总结

以上是大佬教程为你收集整理的iphone – 我应该如何在iOS中动画200多张图片?全部内容,希望文章能够帮你解决iphone – 我应该如何在iOS中动画200多张图片?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: