Iphone: Strongly change orientation from portrait to landscape navigation

Is there a way that we can greatly change the orientation of the application from portrait to landscape while navigating?

I have a requirement that when the controller is pressed from A to B. B should be in the landscape, but my controller A is in the portrait.

+3
source share
3 answers

In your ViewController-B, add these lines of code to 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 works fine if you use the navigation controller to move from A to B.

I used this.

Hope this helps you.

Enjoy the coding :)

+9
source

In - (void)viewWillAppear:(BOOL)animated say:

  //this is to force the application to re-evaluate device orientation //comment the last lines and see //cannot use [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeLeft]; //as "setOrientation" is a private method, and we risk to be kicked out by Apple UIViewController *c = [[[UIViewController alloc]init] autorelease]; [self presentModalViewController:c animated:NO]; [self dismissModalViewControllerAnimated:NO]; 

... but first, in your xib, set the view orientation to what you want.

0
source

in my experience in the last application in which I tried to do the same, I found answers to the stack overflow so as not to force the orientation in the application based on navigation.

 (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) return NO; else return YES; } 

this function will allow you to use the view controller in the desired orientation, in this case I set it for the landscape and forbade rotation in portrait modes.

You will encounter the problem of loading a mode B controller first in orientation to A view controller you. Therefore, I completely changed the orientation of the application to the landscape. Hope this helps.

0
source

All Articles