Disable autorotate on a single subview in iOS8

后端 未结 5 937
遇见更好的自我
遇见更好的自我 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:25

    Okay after some fighting with subviews and transitionCoordinators I've finally figured it out:

    - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator {
        CGAffineTransform targetRotation = [coordinator targetTransform];
        CGAffineTransform inverseRotation = CGAffineTransformInvert(targetRotation);
    
        [coordinator animateAlongsideTransition:^(id context) {
    
            self.drawingView.transform = CGAffineTransformConcat(self.drawingView.transform, inverseRotation);
    
            self.drawingView.frame = self.view.bounds;
        } completion:^(id context) {
        }];
    }
    

    What I do is, I calculate the inverse of the transform applied to the view and then use it to change the transform. furthermore I change the frame with the view bounds. This is due to it being full screen.

提交回复
热议问题