I could suggest a different approach that approaches UISnapBehavior but avoids trying to marry UIKit Dynamics with auto-layout, where you rely on the auto-layout engine to determine the end position of the view. (Obviously, if you knew the final destination, then you simply pause the automatic layout, the binding, and when this binding is completed, you will then apply the restrictions.)
For the bouncing effect, when the view snaps into place, you can use animateWithDuration with the usingSpringWithDamping parameter, for example:
If you also want a little twist when it snaps into place, you can use animateKeyframesWithDuration :
[UIView animateKeyframesWithDuration:1.0 delay:0.0 options:0 animations:^{ [UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:0.5 animations:^{ view.transform = CGAffineTransformMakeRotation(M_PI_4 / 2); }]; [UIView addKeyframeWithRelativeStartTime:0.5 relativeDuration:0.25 animations:^{ view.transform = CGAffineTransformMakeRotation(-M_PI_4 / 4); }]; [UIView addKeyframeWithRelativeStartTime:0.75 relativeDuration:0.125 animations:^{ view.transform = CGAffineTransformMakeRotation(M_PI_4 / 16); }]; [UIView addKeyframeWithRelativeStartTime:0.875 relativeDuration:0.125 animations:^{ view.transform = CGAffineTransformMakeRotation(0); }]; } completion:nil];
This is not exactly UISnapBehavior , but comes close to it quite closely. You can play with the time and the number of spins in the keyframe animation, as well as with the spring damping factor. But this illustrates one approach to getting sticky behavior using block animation.
source share