iPad startup orientation - objective-c

In my info plist, I have defined Supported interface orientations (iPad) as all orientations, and it works. The only problem is if I start in landscape mode, it starts as portrait, but If I rotate and then rotate back, it fixes.
So how can I make it so it adopts to the startup orientation?
thANKS.

You can force the orientation you need by implementing the following in either your didFinishLaunchingWithOptions: or in a view controller's viewWillAppear:.
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO];

The UIViewController that is installed as the root controller via [window addSubview:viewController.view]; should implement the shouldAutorotateToInterfaceOrientation function and return YES to all supported orientations.
The iPad starts the views with Portrait orientation and then rotates all the views by calling willRotateToInterfaceOrientation function with a duration of 0.

I noticed that the order of the interface orientations from the main .plist files is important also. E.g http://monosnap.com/image/jJeImyVp6G3Mq1uXLSAVRA0te2VwgJ Means that at startup the app will be in landscape, with the home button on the right.

Related

Force a single viewcontroller in the story board in landscape

My Project have 2 views 1. Mainview controller 2. Settingview Controller .
I want my main view controller to support all orientations but the setting view controller should be in landscape mode irrespective of the device orientation. Right now I am facing issues like
1. Even if the scene is in landscape mode the view appears as portrait
2. (BOOL)shouldAutorotate , (NSUInteger)supportedInterfaceOrientations not getting fired.
Any help is appreciated.

Where to define the -shouldAutorotate method in iOS 6?

I am trying to define the shouldAutorrotate method, but I don't know where to define it as it's never being called. I have a UITabBarController, with three tabs (each one, with a root navigation controller) in my project. My aim is to disable autorotation in some specfic cases.
Thank you!
OK, solved. What I did: In my topmost navigation controller I defined
-(BOOL)shouldAutorotate {return [self.visibleViewController shouldAutorotate];}
and then, in my next viewController
-(BOOL)shouldAutorotate {return NO;}
Thanks guys!!!
you can write that method in viewcontroller.m file, for which you want to disable autorotation
Here is the code for iOS 6:
#ifdef IOS_NEWER_OR_EQUAL_TO_6
-(BOOL)shouldAutorotate
{
return NO;
}
#endif
Read the iOS 6.0 Release Notes:
Autorotation is changing in iOS 6. In iOS 6, the
shouldAutorotateToInterfaceOrientation: method of UIViewController is
deprecated. In its place, you should use the
supportedInterfaceOrientationsForWindow: and shouldAutorotate methods.
More responsibility is moving to the app and the app delegate. Now,
iOS containers (such as UINavigationController) do not consult their
children to determine whether they should autorotate. By default, an
app and a view controller’s supported interface orientations are set
to UIInterfaceOrientationMaskAll for the iPad idiom and
UIInterfaceOrientationMaskAllButUpsideDown for the iPhone idiom.
A
view controller’s supported interface orientations can change over
time—even an app’s supported interface orientations can change over
time. The system asks the top-most full-screen view controller
(typically the root view controller) for its supported interface
orientations whenever the device rotates or whenever a view controller
is presented with the full-screen modal presentation style. Moreover,
the supported orientations are retrieved only if this view controller
returns YES from its shouldAutorotate method. The system intersects
the view controller’s supported orientations with the app’s supported
orientations (as determined by the Info.plist file or the app
delegate’s application:supportedInterfaceOrientationsForWindow:
method) to determine whether to rotate.
The system determines whether
an orientation is supported by intersecting the value returned by the
app’s supportedInterfaceOrientationsForWindow: method with the value
returned by the supportedInterfaceOrientations method of the top-most
full-screen controller.
The setStatusBarOrientation:animated: method
is not deprecated outright. It now works only if the
supportedInterfaceOrientations method of the top-most full-screen view
controller returns 0. This makes the caller responsible for ensuring
that the status bar orientation is consistent.
So I would first try to implement the behaviour in the app delegate. If that’s too coarse for your use case, I would try to implement the -shouldAutorotate (note the single r!) method for the individual content view controllers. If that does not work (see the quote above), implement this method in your container controller, ie. the tab bar controller or the navigation controller.
See also the WWDC 2012 Session #236, The Evolution of View Controllers on iOS.

Application Lauch in Landscape mode while Simulator/Device is in Portrait mode in ios6

My application window has UITabBarController as a RootViewController. Then UINavigationController as TabBarController's RootViewController. Then another HomeViewController as NavigationController's RootViewController.
When I launch my application in Portrait mode, then HomeViewController's UIView outlets displayed in Landscape mode. All UIView outlets have Landscape mode coordinate. Because return Orientation is Landscape.
I found many Q&A, Blogs. I applied whatever other developers said, but not succeed.
This issue occurs only in ios6 device/iPhone simulator 6.
Right now I am working on Simulator and its show this issue.
Please help me as soon as possible.
Ask me, if I am not capable to explain my question.
Thank you in advance.
In iOS 6, the app looks at your predefined possible orientations from your project file. Check if that only lists landscape, also it uses the shouldAutoRotate method, so you might have to implement that as well.
Check this for more info:
Similar question

iPad launch in landscape issue

When I'm in landscape mode on iPad and trying to launch app I'm getting strange behavior:
My root view controller view is created with dimensionality equal to 768x1024 whereas it should be 1024x768 (device is in landscape mode). Because of that my view hierarchy is corrupted.
View is created by the system (I'm using nib for interface).
Does it bug in iOS, or, maybe, I'm doing something wrong?
Edit: Autoresizing mask is default (everything resizes).
Found a solution here Reporting incorrect bounds in landscape Mode.
I was checking view controller view size in viewDidLoad, while correct sizes available only in viewDidAppear.
That is ok. It is always creates views in portrait orientation when perform rotation to lanscape. So U should implement
- (BOOL) shouldAutorotateToInterfaceOrientation (UIInterfaceOrientation)
- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)
And check in code

Minimum steps to get autorotate to work

I've trying to implement autorotate but my app is not listening to me!
The app has a tab bar controller which supervises 3 view controllers. The tab bar is created programatically in the app delegate. Each of the view controllers has this standard simple method:
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
The app delegate looks like this:
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:gameVC, settingsVC, helpVC, nil];
self.window.rootViewController = self.tabBarController;
In addition, in the target summary area I have all 4 orientations for both the iPad and iPhone activated.
In the simulator, no rotation occurs with either device. I seem to be missing something. Perhaps one more setting is needed? Something out of order? There is nothing else in the project related to rotating views.
The only thing that you seemed to not have said in your response that I can think of is changing the device orientations under your info.plist. I know from personal experience that if you click on the supported device orientations in the target summary area, it might not actually change it in the Info property list. Check and make sure that all four are selected in the property list by doing the following:
Go to your Info.plist
Look under Supported interface orientations and Supported interface orientations (iPad)
Make sure that it has 4 strings under both: Portrait (bottom home button), Portrait (top home button), Landscape (left home button), Landscape (right home button)
User a ViewController for super purpose, and then inheritance it in the each of view controllers. In the super ViewController add this
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return YES;
}
So, you just need to do once to make them autorotate
from http://developer.apple.com/library/ios/#DOCUMENTATION/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/TabBarControllers.html#//apple_ref/doc/uid/TP40011313-CH3-SW26
Tab bar controllers support a portrait orientation by default and do
not rotate to a landscape orientation unless all of the contained view
controllers support such an orientation. When a device orientation
change occurs, the tab bar controller queries its array of view
controllers. If any one of them does not support the orientation, the
tab bar controller does not change its orientation.
#Zack #AlexanderZats This was subtle. I was reading this SO answer which brought me here This 2nd link is a great discussion of different possible reasons an app may not rotate. The last point caught my attention. Sure enough, I was overriding initWithNibName and not calling super on it. I think this ultimately meant that the the VCs were not in the responder chain. A huge thanks to all who gave me ideas and suggestions!