1

Is there any way to disable rotation animation during changing device orientation portrait/landscape in only one UIView and its subviews.

Currently I'm using something like that from this post:

override func viewWillTransitionToSize(size: CGSize,
      withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
    super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)
    CATransaction.begin()
    CATransaction.setDisableActions(true)

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

    }, completion: { (ctx) -> Void in
      CATransaction.commit()
  })

}

But this solution disable all the animations during changing the orientation in every UIView on the screen.

I was trying also to create special NotAnimatedView subclass of UIView with no luck at all:

class NotAnimatedView: UIView {

  override func actionForLayer(layer: CALayer, forKey event: String) -> CAAction? {
    if event == "bounds" || event == "position" {
      return NSNull()
    }
    return super.actionForLayer(layer, forKey: event)
  }


}

The "bounds" and "position" was the two events that was occuring during changing the orientation of the device so I override them and return NSNull() according to Apple Documentation

But It's not working. The NotAnimatedView is also animating. It seems that I don understand something or my understanding of CALayer is wrong. Can somebody put more light on this topic?

Community
  • 1
  • 1
Marcin Kapusta
  • 5,076
  • 3
  • 38
  • 55
  • A possible workaround could be to animate the "non-animating" view backwards. Calculate the frame of the view after rotation as if the view stayed on screen without moving, and animate it to that position in `animateAlongsideTransition`. So it will appear like it's not animating and is stuck on the screen. – Beirs Feb 17 '16 at 14:55

0 Answers0