【问题标题】:UIImageView animationDuration cache delayUIImageView animationDuration 缓存延迟
【发布时间】:2012-08-16 18:21:06
【问题描述】:

我希望在UIImageView 动画停止播放的确切时刻更新UILabel

我在这方面的尝试是使用 -

[self performSelector:@selector(updateLabels) withObject:nil afterDelay:imageView.animationDuration];

updateLabels 是更新标签的方法。

这不适用于前几个动画。但是,它在前 3 或 4 次播放后仍然有效。

我正在使用imageNamed 填充保存动画图像的NSArray。根据我的研究,我注意到imageNamed 缓存了对象。所以我假设前 3 或 4 次运行的延迟是由于缓存的延迟。

有没有办法克服这个问题? (最好不要改变使用 imageNamed,正如我所说的,它在前 3 或 4 之后的所有其他动画周期都可以正常工作)。

【问题讨论】:

    标签: iphone objective-c ios caching uiimageview


    【解决方案1】:

    添加animationDidStop: 在动画停止时采取行动的方法。

      - (void)animationDidStop:(CAAnimation*)animation finished:(BOOL)finished 
     {
        //Update your label
     }
    

    注意不要忘记在uiimageview.animation中添加setDelegateself

    【讨论】:

    • 感谢@Prince,但我正在使用 UIImageView 并且没有任何 CAAnimation。这还能实现吗?
    【解决方案2】:

    你试过这个吗:(不是更好的实现,但是)//作为例子

    在 h.file 中:

    UIImageView *im;
    

    im .m - 文件:

     -(void) viewDidLoad
     {
        [super viewDidLoad];
    
        im = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
       UIImage *firstIm = [UIImage imageNamed:@"foo.png"];  // example pictures
       UIImage *secondIm = [UIImage imageNamed:@"bar.png"];
       im.animationImages = [NSArray arrayWithObject:firstIm, secondIm, nil];
       im.animationDuration = 1.0;
       im.animationRepeatCount = 4;
       [im startAnimating];
       [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateLabels) userInfo:nil repeats:YES];
    
    }
    
    -(void) updateLabels
    {
       if (![im isAnimating]])
       {
          //Update your label
       }
    }
    

    它使用-imageNamed 图片,但在这种情况下执行的不是更好的结束动画检查。无论如何,它可能对你有帮助。

    【讨论】:

    • 感谢@frankWhite,是的,我曾尝试使用isAnimating 进行类似的操作。但它不起作用,因为isAnimating 始终处于YES 状态。类似于this SO link
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-17
    • 2019-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多