UIView animations prevented after returning from background ios8 (Rubymotion)

155 views Asked by At

I'm trying to restart a UIView animation after the user returns to the app from the background.

Here's the animation:

  def animate_glow
    UIView.animateWithDuration(GLOW_SPEED,
      delay: 0.0,
      options: UIViewAnimationOptionRepeat |
               UIViewAnimationOptionAutoreverse |
               UIViewAnimationOptionAllowUserInteraction,
      animations: -> {
        @swipe_glow.transform = CGAffineTransformMakeScale(GLOW_SCALE, GLOW_SCALE)
      },
      completion: nil
    )
  end

Listening for UIApplicationWillEnterForegroundNotification I'm trying to call animate_glow but my animations don't restart/are prevented. Logs show that the notification listener is being called and that UIView.areAnimationsEnabled returns true. I've also tried removing the view referenced by @swipe_glow from superview and creating a new one, and calling animate_glow This also has no effect on the actual animation (though a new UIView can be created without issue).

Can anyone explain this?

1

There are 1 answers

0
Vann2108 On BEST ANSWER

A solution I found, just in case anyone else finds this problem:

UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse |

These lines appeared to be the cause of the problem, as when the animation returned from the background the animations were being set to their end point (GLOW SCALE). The system then attempted to restart the animation but found no change to animate.

Two possible solutions: Listen for UIApplicationDidEnterBackground and in the handler reset the view to be animate's position back to it's origin.

Or change the animation blocks to animate & reverse methods that call each other in their completion: blocks.

Hope this helps someone!