Objective-c – iphone: Forcefully change orientation from portrait to landscape on navigation

iphonelandscapeobjective corientationuinavigationcontroller

Is there any way that we can Forcefully change app orientation from portrait to landscape while navigating ?

I have a requirement that while pushing controller from A to B. B should be in landscape but my A controller is in portrait.

Best Answer

In your ViewController-B add this lines of code in viewDidLoad:

  [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];

  float   angle = M_PI/2;  //rotate 180°, or 1 π radians
  self.view.layer.transform = CATransform3DMakeRotation(angle, 0, 0.0, 1.0);

This code is working fine if you are using navigation controller to move from A to B.

I have used this.

Hope this will help you.

Enjoy Coding :)