1

I am implementing the following solution to pause a UIView animation:

https://stackoverflow.com/a/3003922/1014164

Pausing and Resuming animation is working, HOWEVER:

After I have paused my animation, and proceed to rotate my device, other views on the screen are starting to resize, but for some reason, this freezes all interaction and views on the screen - orientation change no longer works, buttons are non-responsive.

IF, however, I rotate the device while animation is in motion, everything works fine as it should.

Another test I made was to take out the auto-resizing of the outer view which houses the view being animated, and this allows things to work properly.

It seems there is some conflict between the paused layers and the auto-resizing of the parent layer. I just can't figure out how to get around it.

Any help would be greatly appreciated.

Community
  • 1
  • 1
cohen72
  • 2,830
  • 29
  • 44

3 Answers3

2

As you discovered, the fact that the view's layer is paused means that it can't be animated to the new size when you rotate the device, and this freezes the UI.

There is however a cleaner solution that doesn't resort to abandonning iOS's nice resize animations or autolayout. You can create an intermediate layer underneath the root layer, and place all the other layers under that. You should then use this intermediate layer to control the speed of the animations (or to pause them).

Since iOS won't be resizing your sub layers when the device is rotation, it doesn't matter than the layer is paused.

(I realise that this answer is very late, but it may still serve someone).

tarmes
  • 15,366
  • 10
  • 53
  • 87
1

Since orientation changes cause animations on other views being used, I had to disable the autoresize mask for these views, thereby avoiding the conflict when pausing the animations. Those views that were being autoresized were resized manually in the orientation notification methods.

cohen72
  • 2,830
  • 29
  • 44
1

In follow-up to @tarmes’s, you can also try something like:

override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator)
{
    super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)

    if let myView = self.view
    {
        let currentLayerSpeed = myView.layer.speed

        coordinator.animateAlongsideTransition(
        {
            (context) -> Void in

            // Animating alongside… nothing to animate.
            if currentLayerSpeed == 0
            {
                myView.layer.speed = 1.0
            }
        })
        {
            // Completion
            (context) -> Void in

            // Rotation animation completed – resetting the layer speed
            myView.layer.speed = currentLayerSpeed
        }
    }
}
Aral Balkan
  • 5,981
  • 3
  • 21
  • 24