大佬教程收集整理的这篇文章主要介绍了iphone – 我应该如何在iOS中动画200多张图片?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我曾尝试每隔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]; }
以上是大佬教程为你收集整理的iphone – 我应该如何在iOS中动画200多张图片?全部内容,希望文章能够帮你解决iphone – 我应该如何在iOS中动画200多张图片?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。