UIImageView isAnimating 在 4.0 SDK 中是否中断?

发布于 2024-11-15 09:44:14 字数 3709 浏览 4 评论 0原文

以下代码在使用 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");
    }
}

还有其他人看到这个吗?

The following code used to work when built with iOS 3.x. Now with 4.x it doesn't work. In other words, I can run two identical apps, on the same device, one built against a per-4.x release and the other with 4.3, and in the latter, isAnimating doesn't change values unless the screen is tapped or the orientation changes.

Here is the relevant code. I started with a View based template in 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");
    }
}

Is anyone else seeing this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青柠芒果 2024-11-22 09:44:14

如果你设置一个计时器,这会更有效。您面临的问题可能不是 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;
 }

This would be much much more efficient if you setup a timer. The problem you're facing may not be that UIImageView is broken but rather that the image view takes a very long time to load the animation.

I'd recommend something like this.

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;
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文