There are many situations where you need to “shake” a UIView.
(For example, “draw the attention of the child user to the control”, “connection is slow”, “user enters invalid input”, etc.)
Can this be done using UIKit Dynamics?
So you have to ...
take a representation of say at 0,0
add spring concept
give it a push, say "left"
it should lean back and forth on spring, eventually settling down again at 0.0
Is it possible? I could not find an example in Apple demos. Greetings
Note that, as Niels explains below, spring is not necessarily the “physical sensation” you want for some of these situations: in other situations, it may be ideal. As far as I know, the physics of all in native iOS applications (for example, messages, etc.) now uses UIKit Dynamics, so for me it’s worth having the “UIView bouncing on spring” handle.
To be clear, of course, you can do something “similar,” just with the animation. Example...
But that just doesn't have the same “physical feel” as the rest of iOS.
-(void)userInputErrorShake { [CATransaction begin]; CAKeyframeAnimation * anim = [CAKeyframeAnimation animationWithKeyPath:@"transform"]; anim.values = @[ [NSValue valueWithCATransform3D: CATransform3DMakeTranslation(-4.0f, 0.0f, 0.0f) ], [NSValue valueWithCATransform3D: CATransform3DMakeTranslation(4.0f, 0.0f, 0.0f) ] ]; anim.autoreverses = YES; anim.repeatCount = 1.0f; anim.duration = 0.1f; [CATransaction setCompletionBlock:^{}]; [self.layer addAnimation:anim forKey:nil]; [CATransaction commit]; }
ios ios7 user-experience game-physics uikit-dynamics
Fattie Jun 22 '14 at 21:46 2014-06-22 21:46
source share