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
  • 31,342
  • 6
  • 71
  • 100
iOS
  • 3,370
  • 3
  • 35
  • 76

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,735
  • 2
  • 29
  • 44
1

Add this to your ViewController.m

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        return UIInterfaceOrientationIsLandscape(interfaceOrientation);   
}
Thunder Rabbit
  • 5,282
  • 8
  • 43
  • 80
Hiren
  • 12,632
  • 7
  • 53
  • 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,854
  • 1
  • 17
  • 17