在iOS动画中获取当前帧

在iOS动画中获取当前帧,ios,objective-c,animation,uiimageview,core-animation,Ios,Objective C,Animation,Uiimageview,Core Animation,这是我的密码: -(void)play { animation = [CAKeyframeAnimation animationWithKeyPath: @"contents"]; for (UIImage *image in folder.images) { [images addObject:(id)image.CGImage]; } animationArray = [images subarrayWithRange:NSMakeRange(

这是我的密码:

-(void)play {
    animation = [CAKeyframeAnimation animationWithKeyPath: @"contents"];
    for (UIImage *image in folder.images) {
        [images addObject:(id)image.CGImage];
    }
    animationArray = [images subarrayWithRange:NSMakeRange(selected, selectedEnd - selected)];
    timeBetweenAnimation = 1.0/framesPerSecond;
    totalAnimationTime = folder.images.count * timeBetweenAnimation;
    animation.duration = totalAnimationTime;
    animation.values = animationArray;
    animation.delegate = self;
    beforeAdd = CACurrentMediaTime();
    [displayImage.layer addAnimation:animation forKey:@"contents"];
    afterAdd = CACurrentMediaTime();
}

-(void)animationDidStart {
    afterStart = CACurrentMediaTime();
}
我正在使用核心动画制作一组图像的动画,我想在暂停图像时获得动画中的当前图像。我意识到这样做的一种方法是使用播放时间/总持续时间的计时比率从animationArray获取图像,但我无法捕获开始时间。在调用addAnimation:forKey:之前和之后,以及动画确实开始之后,我尝试使用CACurrentMediaTime捕捉开始时间,但它不准确,特别是当我有大量图像时。对于较大的图像阵列,添加前和添加后的时间至少间隔一秒。另外,与我的图像阵列的大小无关,afterStart在0.04到0.08秒之间

在最坏的情况下,我可以使用后启动开始时间。但是,如果我试图在1秒内设置100幅图像的动画,那么使用此方法获取图像将不准确4帧。因此,我要么需要一种不使用计时的方法来获取动画的当前帧,要么需要一种获得更精确的开始时间的方法。这可能吗

注意:我不想使用UIImageView动画来实现这一点,因为该动画技术在帧之间没有平滑过渡。如果有一种方法可以使用UIImageView动画在帧之间平滑过渡,我会重新考虑,尽管我很确定在计算开始时间时仍然会有问题