我有超过 200 张图像我想在大约 10 秒的空间内制作动画。我尝试animationImages
通过将图像加载到数组中然后调用该startAnimating
方法来使用。这在模拟器中运行良好,但导致 iPad 崩溃。
我尝试NStimer
每 1/25 秒调用一次,并在每次定时器触发时更改图像。这比以前的方法表现更好,它在模拟器中运行良好,但在 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];
}