Objective c UIImageView是否在4.0 SDK中实现了动画化突破?
以下代码在使用iOS 3.x构建时使用。现在有了4.x,它就不起作用了。换句话说,我可以在同一台设备上运行两个相同的应用程序,一个是针对per-4.x版本构建的,另一个是针对4.3版本构建的,在后者中,除非点击屏幕或方向发生变化,否则isAnimating不会改变值 这是相关代码。我从Xcode中基于视图的模板开始Objective c UIImageView是否在4.0 SDK中实现了动画化突破?,objective-c,ios,uiimageview,uiimage,Objective C,Ios,Uiimageview,Uiimage,以下代码在使用iOS 3.x构建时使用。现在有了4.x,它就不起作用了。换句话说,我可以在同一台设备上运行两个相同的应用程序,一个是针对per-4.x版本构建的,另一个是针对4.3版本构建的,在后者中,除非点击屏幕或方向发生变化,否则isAnimating不会改变值 这是相关代码。我从Xcode中基于视图的模板开始 - (void)viewDidLoad { [super viewDidLoad]; iv.animationImages = [NSArray arrayWithO
- (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;
}
与问题无关,但很抱歉,这是一个非常糟糕的代码。你应该使用循环来创建数组。我不想弄乱一个可变数组。或者你有别的方法吗?我更喜欢可变数组而不是这个。虽然这是个人的选择。你的代码在iOS 4.2模拟器和4.2.1设备上运行得很好。我刚刚运行了一些测试(将图像减少到三个),看起来至少需要一分钟,有时是预期延迟的4倍,然后isAnimating变为否。如果你没有看到,例如。,如果isAnimating==YES的持续时间正好且仅等于animationDuration*animationRepeatCount,那么?