以下代码在使用iOS 3.x构建时可以正常工作。现在使用4.x则无法使用。换句话说,我可以在同一设备上运行两个相同的应用程序,一个针对per-4.x版本构建,另一个针对4.3版本,而在后者中,除非轻按屏幕或按下鼠标,否则isAnimating不会更改值。方向改变。
这是相关的代码。我从Xcode中基于视图的模板开始。
- (void)viewDidLoad {
[super viewDidLoad];
iv.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"timer00.png"],
[UIImage imageNamed:@"timer01.png"],
[UIImage imageNamed:@"timer02.png"],
[UIImage imageNamed:@"timer03.png"],
[UIImage imageNamed:@"timer04.png"],
[UIImage imageNamed:@"timer05.png"],
[UIImage imageNamed:@"timer06.png"],
[UIImage imageNamed:@"timer07.png"],
[UIImage imageNamed:@"timer08.png"],
[UIImage imageNamed:@"timer09.png"],
[UIImage imageNamed:@"timer10.png"],
[UIImage imageNamed:@"timer11.png"],
[UIImage imageNamed:@"timer12.png"],
[UIImage imageNamed:@"timer13.png"],
[UIImage imageNamed:@"timer14.png"],
[UIImage imageNamed:@"timer15.png"],
[UIImage imageNamed:@"timer16.png"],
[UIImage imageNamed:@"timer17.png"],
[UIImage imageNamed:@"timer18.png"],
[UIImage imageNamed:@"timer19.png"],
[UIImage imageNamed:@"timer20.png"],
[UIImage imageNamed:@"timer21.png"],
[UIImage imageNamed:@"timer22.png"],
[UIImage imageNamed:@"timer23.png"],
[UIImage imageNamed:@"timer24.png"],
[UIImage imageNamed:@"timer25.png"],
[UIImage imageNamed:@"timer26.png"],
[UIImage imageNamed:@"timer27.png"],
[UIImage imageNamed:@"timer28.png"],
[UIImage imageNamed:@"timer29.png"],
[UIImage imageNamed:@"timer30.png"],
[UIImage imageNamed:@"timer31.png"],
[UIImage imageNamed:@"timer32.png"],
[UIImage imageNamed:@"timer33.png"],
[UIImage imageNamed:@"timer34.png"],
[UIImage imageNamed:@"timer35.png"],
[UIImage imageNamed:@"timer36.png"], nil];
iv.animationDuration = 5.0;
iv.animationRepeatCount = 1;
[iv startAnimating];
timer = [NSTimer scheduledTimerWithTimeInterval:0.5
target:self
selector:@selector(periodicallyUpdateView)
userInfo:nil
repeats:YES];
}
- (void)periodicallyUpdateView {
if ([iv isAnimating]) {
NSLog(@"it is animating");
}
else {
NSLog(@"it is NOT animating");
}
}
还有其他人看到吗?
最佳答案
如果您设置计时器,这将大大提高效率。您面临的问题可能不是UIImageView损坏了,而是图像视图需要很长时间才能加载动画。
我建议这样的事情。
NSTimer *imageTimer;
int animationCount;
- (void)startAnimation
{
imageTimer = [NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(switchImage) userInfo:nil repeats:YES];
}
- (void)switchImage
{
NSString *imageName = [NSString stringWithFormat:@"timer%i" , animationCount];
UIImage *image = [UIImage imageNamed:imageName];
someImageView.image = image;
}