Disable autorotate on a single subview in iOS8

后端 未结 5 939
遇见更好的自我
遇见更好的自我 2020-12-10 07:33

I\'m writing a drawing app and I don\'t want the drawing view to rotate. At the same time, I want other controls to rotate nicely depending on the orientation of the device.

5条回答
  •  隐瞒了意图╮
    2020-12-10 08:11

    Dimitri's answer worked perfectly for me. This is the swift version of the code in case someone needs it...

    override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
      let targetRotation = coordinator.targetTransform()
      let inverseRotation = CGAffineTransformInvert(targetRotation)
    
      coordinator.animateAlongsideTransition({ context in
        self.drawingView.transform = CGAffineTransformConcat(self.drawingView.transform, inverseRotation)
        self.drawingView.frame = self.view.bounds
        context.viewControllerForKey(UITransitionContextFromViewControllerKey)
      }, completion: nil)
    }
    

提交回复
热议问题