0

I am developing an iPhone application and the application should work only in landscape mode. But, when I rotate the device or simulator, the viewContoller's mode changes from landscape to portrait. I want the viewController to maintain in landscape mode, though the device or simulator is portrait. How could I make this happen? Thanks in advance.

Christofer Eliasson
  • 32,939
  • 7
  • 74
  • 103
iOS
  • 3,526
  • 3
  • 37
  • 82

4 Answers4

1

Override this method in your view controller:

// Override to allow orientations other than the default portrait orientation.
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientation, NO for other;
}
rockeye
  • 2,765
  • 2
  • 30
  • 44
1

Add this to your ViewController.m

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        return UIInterfaceOrientationIsLandscape(interfaceOrientation);   
}
Thunder Rabbit
  • 5,405
  • 8
  • 44
  • 82
Hiren
  • 12,720
  • 7
  • 52
  • 72
0

change in info_plist .. Supported interface orientations Set only landscape

Ayaz
  • 1,398
  • 15
  • 29
-1

Override this method in all your ViewControllers:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight ||
            interfaceOrientation == UIInterfaceOrientationLandscapeLeft);

}

And also see Only support for landscape Interface orientation

Community
  • 1
  • 1
Léon Rodenburg
  • 4,894
  • 1
  • 18
  • 18