Okay, I've got my normal app which is in portrait mode. I can force my app to go to landscape mode for a view (using navigationcontroller and viewcontroller) like this:
- (void)viewWillAppear:(BOOL)animated {
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
}
But then when I go back to the main menu (tableview) it goes straight back to portrait. I try this code:
- (void)viewWillAppear:(BOOL)animated {
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
}
But that doesn't work..
Any ideas?
1 Swipe down from the top-right corner of your screen to open Control Center. 2 Tap the Portrait Orientation Lock button to make sure that it's off. 3 Turn your iPhone sideways.
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. If the screen still doesn't rotate, try a different app — like Safari or Messages — which are known to work in landscape mode.
1 Swipe up from the bottom edge of your screen to open Contol Center. 2 Tap the Portrait Orientation Lock button to make sure that it's off. 3 Turn your iPhone or iPod touch sideways. If the screen still won't rotate, try another app — like Safari or Messages — which are known to work in landscape mode. See More....
Learn more. If you have an iPhone Plus, and want the Home screen to rotate, go to Settings > Display & Brightness and set Display Zoom to Standard. If you have an iPad with a Side Switch, you can set the Side Switch to work as a rotation lock or mute switch. Go to Settings > General.
Take a look at the function shouldAutorotateToInterfaceOrientation: in the UIViewController class. This function returns YES if the orientations are supported by your UIView. If you return YES only to the landscape orientation, the iPhone will automatically be put in that orientation.
The following code should do it. Put it in the UIViewController that controls the view that you want to put in landscape mode.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscape);
}
To get this to work, I added this to the rootviewcontroller:
- (void)viewWillAppear:(BOOL)animated {
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
}
This seems to be working now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With