CAKeyframeAnimation Manual Progress

前端 未结 2 585
南方客
南方客 2021-02-04 20:31

I have a UIView whose backing layer has a CAKeyframeAnimation with a simple straight line path set as its `path`.
Can I have the animation \"frozen\", so to speak, and man

2条回答
  •  [愿得一人]
    2021-02-04 20:42

    This is based on what Jonathan said, only a bit more to the point. The animation is set up correctly, but the slider action method should be as follows:

    - (void)sliderDidSlide:(UISlider *)slider 
    {
        // Create and configure a new CAKeyframeAnimation instance
        CAKeyframeAnimation *animation = ...;
        animation.duration = 1.0;
        animation.speed = 0;
        animation.removedOnCompletion = NO;
        animation.timeOffset = slider.value;
    
        // Replace the current animation with a new one having the desired timeOffset
        [_label.layer addAnimation:animation forKey:@"LabelPathAnimation"];
    }
    

    This will make the label move along the animation's path based on timeOffset.

提交回复
热议问题