I have created an app for ipad in which the homescreen should be displayed only in portrait mode. So i have used the below code in viewdidload.
[[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait];
but it is not working. I am using ios 7 with xcode 5. If i open my app from landscape mode it shouuld automatically turn to portrait mode. but i am getting like this:
but it should be like this:
can any one help me to solve this issue. Thanks in advance.
Following code is about to transform a navigationController view from Portrait to Landscape programmatically:
Just hope to provide you some other ideas.
From you screenshots I can see that your app is tab base. Few days earlier I faced same problem. I solved it. I asked a question almost same to your. Then after a few hours of reading I solved the problem. There is the link to my question and answer.
copy this code in your viewdidload
set BOOL according to your requirement
This method is deprecated. You cannot use this method anymore.
https://stackoverflow.com/a/12813644/1405008
Above link gives detail on how to provide portrait only mode for
UIViewController
.If you pushed into
NavigationViewController
then try this.https://stackoverflow.com/a/16152506/1405008
There are a lot of similar questions and answers on SO, but somehow none of them worked for me, as I needed to allow only portrait mode on iPhone, and only landscape mode on iPad, so sharing my solution:
Remove all methods related to device orientation (
shouldAutoRotate, supportedInterfaceOrientations, preferredInterfaceOrientations
, etc) as they might be conflicting with each otherIn project settings enable all 4 modes: Portrait, Upside Down, Landscape left, Landscape Right
Chose a method for identifying device type (iPhone or iPad). I am using
UIScreen.mainScreen().bounds.height which
is not ideal but suits my needsPlace the following in AppDelegate
Tested on Xcode 7.1.1 all iPhone and iPad simulators running iOS9.1