Note that there are some explanatory texts on larger screens.

plurals
  1. POUIViewAnimation only completing 180 deg rotation
    primarykey
    data
    text
    <p>I was looking for an indefinite animation technique for my loading animation. The user clicks login, and whilst the JSON stuff is taking care of itself, the spinner spins and then eventually presents a new view controller or login error. I found a great <a href="https://stackoverflow.com/questions/9844925/uiview-infinite-360-degree-rotation-animation">code snippet</a> given by <strong>Nate</strong>. </p> <p>The code is given by: </p> <pre><code>// an ivar for your class: BOOL animating; - (void) spinWithOptions: (UIViewAnimationOptions) options { // this spin completes 360 degrees every 2 seconds [UIView animateWithDuration: 0.5f delay: 0.0f options: options animations: ^{ self.imageToMove.transform = CGAffineTransformRotate(imageToMove.transform, M_PI / 2); } completion: ^(BOOL finished) { if (finished) { if (animating) { // if flag still set, keep spinning with constant speed [self spinWithOptions: UIViewAnimationOptionCurveLinear]; } else if (options != UIViewAnimationOptionCurveEaseOut) { // one last spin, with deceleration [self spinWithOptions: UIViewAnimationOptionCurveEaseOut]; } } }]; } - (void) startSpin { if (!animating) { animating = YES; [self spinWithOptions: UIViewAnimationOptionCurveEaseIn]; } } - (void) stopSpin { // set the flag to stop spinning after one last 90 degree increment animating = NO; } </code></pre> <p>When the user clicks 'login' the <code>startSpin</code> method is called, and the JSON stuff is sent. In my JSON post method I have this: </p> <pre><code>if(success == 1) { //Present the new view controller } else { [self performSelectorOnMainThread:@selector(stopSpin) withObject:nil waitUntilDone:NO]; [self performSelectorOnMainThread:@selector(hideAnimation) withObject:nil waitUntilDone:NO]; } </code></pre> <p>This animation method has worked great for an uploading page I use later in my app. However, for this application, it only spins 180 degrees then stops. Then the next page/error eventually loads after a time interval of the inanimate image. Does anybody have any idea as to why this is happening? I dont think it is anything to do with the view controller part because it stops spinning even when the login has failed (no view controller to be presented). I call my <code>startSpin</code> method on the click of a button using: </p> <pre><code>[self performSelectorOnMainThread:@selector(showAnimation) withObject:nil waitUntilDone:NO]; [self performSelectorOnMainThread:@selector(startSpin) withObject:nil waitUntilDone:NO]; </code></pre> <p>Where show animation is just a method which un-hides the view. </p> <p>Any thoughts appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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