UIView animation horizontally using UIDynamicAnimator

I looked through the documentation, and I am ashamed to say that I am confused.

Scenario :

I have a UIView that acts as a container for 3 UIButtons . This container initially has borders {0, 0, 35, 35} , with each button inside with the same coordinates (with alpha 0). For a specific user action, the container changes its borders to {0, 0, 100, 35} , and the button is animated in x-origin 5, 35 and 65, respectively, using alpha 1, so that they spread inside the resized container. I see this as an extended state of the container. The same user action switches it back to its original compressed state.

Purpose :

I am currently doing this using the [UIView animateWithDuration:] block, but would like to use UIDynamicAnimator to add a bouncy effect, so when I switch to the expanded state, the container resizes with a rollback (resizes a bit more, and bounces back to the target borders) , as well as the buttons bounce (move a little further and return to the target borders).

The Confusion :

UIDynamicAnimator , UIDynamicBehavior , UIAttachmentBehavior , UIDynamicItem ..... all this makes my understanding of UIKitDynamic overflow. I think I should use UISnapBehavior , but I do not know how to do this.

+2
ios uiview uikit-dynamics uidynamicanimator
Apr 17 '14 at 5:36 on
source share
1 answer

As it turned out, the use of UIDynamicAnimator and all other dynamic animations is not required. All I need is a class method of animateWithDuration:delay:usingSpringWithDamping: initialSpringVelocity: options: animations: completion: Just use it instead of the simple animateWithDuration: method, and it gives the exact behavior I wanted to achieve.

Code example:

  [UIView animateWithDuration:0.4 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:0.5 options:0 animations:^{ //Animation code } completion:nil]; 
+8
May 29 '14 at 6:01
source share



All Articles