Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

force landscape ios 7

I've tried to following methods to force landscape on one my views:

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationLandscapeLeft;
}

- (BOOL)shouldAutorotate{
    return YES;
}

Neither did work. Note that I'm testing on the simulator and on an iPad.

Thanks

like image 554
diogo.appDev Avatar asked Sep 30 '13 13:09

diogo.appDev


People also ask

How do I put my iPhone 7 in landscape mode?

Swipe down from the top-right corner of your screen to open Control Center. Tap the Portrait Orientation Lock button to make sure that it's off. Turn your iPhone sideways.

Can you force an app into landscape mode?

When on the main screen, under the orientation section, you will see a number of options like 'Auto-rotate OFF', 'Auto-rotate ON', 'Forced Portrait' and 'Forced Landscape'. As the names suggest, you can use these buttons as one-tap shortcuts to toggle the orientation of your device.


1 Answers

Here is how I forced one of my views to be Landscape using NavigationViewController:

  1. Implemented this answer: https://stackoverflow.com/a/12662433/2394787

  2. Imported message in the View controller: objc/message.h

  3. Added this line of code in the viewDidLoad method:

objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationLandscapeLeft);

Hope it helps someone.

like image 194
diogo.appDev Avatar answered Sep 30 '22 23:09

diogo.appDev