UIView animateKeyFramesWithDuration 没有在正确的时间开始

UIView animateKeyFramesWithDuration not starting at correct times

我很困惑为什么这不起作用。我这三个事件接连发生。第一个缩小和缩小图像,第二个在背景中淡入淡出,第三个为第一张图像设置动画。但它实际上是反过来发生的吗?我是不是做了什么傻事?

    [UIView animateKeyframesWithDuration:2.0 delay:0.0 options:UIViewKeyframeAnimationOptionBeginFromCurrentState animations:^{
        [UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:0.25 animations:^{
            [v setFrame:CGRectMake(self.view.center.x - 125, self.view.center.y - 125, 250, 250)];
        }];
        [UIView addKeyframeWithRelativeStartTime:0.50 relativeDuration:0.75 animations:^{
            [UIView transitionWithView:self.fullView
                              duration:0
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:NULL
                            completion:NULL];

            [self.fullView setHidden:NO];
        }];
        [UIView addKeyframeWithRelativeStartTime:1.50 relativeDuration:0.5 animations:^{
            v.animationImages = [self.imageDict objectForKey:id];
            v.animationRepeatCount = 1;
            [v startAnimating];
        }];
    }
    completion:nil];

编辑// 除了拼写错误(addKeyFrameWithRelativeStartTime 为 1.50)之外,第三个块无法正常工作,因为 UIImageView startAnimating 方法需要放在完成块中。

您的代码看起来很可疑。您添加的最后一个关键帧动画的相对开始时间为 1.5。那有什么作用?它应该在 0 到 1 的范围内。

来自苹果文档,

frameStartTime

The time at which to start the specified animations. This value must be in the range 0 to 1, where 0 represents the start of the overall animation and 1 represents the end of the overall animation. For example, for an animation that is two seconds in duration, specifying a start time of 0.5 causes the animations to begin executing one second after the start of the overall animation.

帧持续时间

The length of time over which to animate to the specified value. This value must be in the range 0 to 1 and indicates the amount of time relative to the overall animation length. If you specify a value of 0, any properties you set in the animations block update immediately at the specified start time. If you specify a nonzero value, the properties animate over that amount of time. For example, for an animation that is two seconds in duration, specifying a duration of 0.5 results in an animation duration of one second.

我很确定将值固定在范围内会有一些好的改变。但是,我不确定它是否能解决您的问题,因为我不理解您的动画代码。