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.
Asked
Active
Viewed 1,718 times
4 Answers
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
-
The OP states that he doesn't want support for portrait mode, so just returning YES won't help. – Léon Rodenburg Dec 22 '11 at 09:18
-
Obviously... I just pointed the method he has to override. I did not write the full code... – rockeye Dec 22 '11 at 09:20
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
-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