Search code examples
animationios4uislider

stopping an animation on the spot


i have a UISLider that is being animated - going across the screen over a 91.0 second period. i would like to be able to stop the animation spot on.

the code:

 [UIView animateWithDuration:91.0
        delay:0.0
        options:UIViewAnimationOptionRepeat|
                    UIViewAnimationOptionAllowUserInteraction|
            UIViewAnimationOptionBeginFromCurrentState
        animations:^{[UIView setAnimationDuration:91.0];
                 [myUISlider setValue:91.0];}
            completion:nil];

    [UIView commitAnimations];
  • one way to stop an animation is setting a new value. however, i cannot READ the current value/position of the slider DURING the animation. when accessing mySlider.value i get the target value (where the animation will end, i.e 91.

i did some digging up and came across the continuous flag which fires up an action method and is setup up to YES by default. from the developer reference:

"...if YES, the slider sends update events continuously to the associated target’s action method...".

however, the value here is, again, 91.0...

thank you for your time.

yours,

~nir.


Solution

  • If you ask the UISlider's layer for its -presentationLayer, you can then interrogate that copy of the layer for the near real-time animated properties. From the CALayer documentation:

    Returns a copy of the layer containing all properties as they were at the start of the current transaction, with any active animations applied.