Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The easiest way I know is to use Core Animation. Basically, you create an Core Animation Block, then do an rotation transform and setup and repeat count. Core Animation then takes care of everything that's needed to do this wobbling effect.</p> <p>To start an Core Animation block, just do:</p> <pre><code>[UIView beginAnimations:@"any string as animationID" context:self]; [UIView setAnimationRepeatCount:10]; // rotate [UIView commitAnimations]; </code></pre> <p>not tested. But it can be that you will also have to do:</p> <pre><code>[UIView setAnimationBeginsFromCurrentState:YES]; </code></pre> <p>A.F.A.I.K. setAnimationRepeatCount will have the effect that the animation gets done, undone, done, undone, done, undone, done... as many times as you specify. So you may want to first rotate to left with no repeat count, and then from this point start wobbling with repeat count. When done, you may want to rotate back to the identity transform (= no rotation and scaling applied).</p> <p>You can chain animations by setting the animation delegate with </p> <pre><code>[UIView setAnimationDelegate:self] </code></pre> <p>and then </p> <pre><code>[UIView setAnimationDidStopSelector:@selector(myMethod:finished:context:)]; </code></pre> <p>and as soon as the animation stops, that method will be called. See the UIView class documentation for how to implement that method that will be called when the animation stops. Basically, inside that method you would perform the next step (i.e. rotating back, or anything else), with an new animation block but same context and animation ID, and then (if needed) specify another didStopSelector.</p> <p><strong>UPDATE:</strong></p> <p>You may want to check out:</p> <pre><code>[UIView setAnimationRepeatAutoreverses:YES]; </code></pre> <p>this will wobble back and forth automatically.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload