How comes this UIViewController is always displayed in Portrait Mode? - objective-c

When my device is in landscape mode and I modally present a view controller, this is always displayed in portrait mode, which is what I want.
However, I don't understand why other views (modally presented) are always displayed in landscape mode instead (if the current orientation of the device is landscape). The code I use is the same for all my view controllers, and the xib file orientation property is always Portrait.
This is how I push the view controller which works (it is never displayed in landscape mode):
- (IBAction)showImport:(id)sender
{
CMImportExportViewControlleriPhone *importController = [[CMImportExportViewControlleriPhone alloc] initWithNibName:#"Import-Export-iPhone" bundle:nil];
[importController setLayoutViewController:self];
//[importController setDelegate:self];
[self presentModalViewController:importController animated:YES];
[importController release];
}
thanks

If this is initial view controller and you have settings in plist file to start application in portrait mode then it would display in portrait mode doesn;t matter what is your device orientation. When you put your device in landscap mode and present new view controller, it will be landscap as it follows the status bar orientation! Before presenting new view controller try reseting status bar to portrait mode and then present new view controller. It will be presented in portrait mode! I had this similar issue in iOS 6.0.

Related

Landscape mode with modal view

I am trying to add a modal view to my ipad app. All views are supposed to be in landscape mode.
For style I chose form or a page sheet.
Here is the problem. When I add modal view to my view with the following code:
TempController *tmpViewController = [[TempController alloc] initWithNibName:#"TempView" bundle:nil];
tmpViewController.modalPresentationStyle = UIModalPresentationPageSheet;
[self presentModalViewController:tmpViewController animated:YES];
My modal view is displayed in landscape mode, but the view below it is displayed in Portrait. After modal gets dismissed, view is still in potrait. If I don't attach modal to the view, the view is displayed fine, in landscape mode.
I played with statusBarOrientation and shouldAutootateToInterfaceOrientation, but still no luck. I am running xcode 4.4.1 on Mountain Lion
update: this is my shouldAutorotateToInterfaceOrientation:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
return YES;
}
return NO;
}
A quick note: presentModalViewController:animated: is deprecated. Apple recommend using presentViewController:animated:completion:.
To make sure I understand the question, the view controller that presents the modal view controller displays correctly in landscape mode, but then as soon as it presents the modal it changes itself to portrait mode, even though the modal view controller also displays correctly in landscape? Is this happening with an iPhone/iPod touch or iPad? What does your code look like for the shouldAutoRotateToInterfaceOrientation method of the presenting view controller?

Orientation doesnt work when i add tabBarController in splitView

In my app i have added tabBarController in split View's RootViewController.In that portrait mode works fine but it orientation doesn't change to landscape mode. Orientation doesn't change in landscape when i add tabBarController in rootViewController.
Please suggest me the way to do this.
Make sure that all your view controllers contained in the tab bar controller can be display in all orientations. see Technical Q&A QA1688 for more informations. https://developer.apple.com/library/ios/#qa/qa1688/_index.html
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}

A view controller is in landscape mode, but I'm getting the frame from portrait mode?

I have a settings view controller with a table view. The table view is supposed to set its frame to be the frame of the view controller. My app only supports landscape mode, so that's the orientation I'm always in.
However, when the settings view controller loads, the table view has the portrait mode frame of the view controller, even though it's in landscape (360 by 480 when it should be 480 by 360).
Additionally, when I checked to see if the device thought it was in portrait mode, it returned true.
What is causing the problem and how can I fix it?
when you call [UIView init] it will default to the screen size of your device in portrait mode (same goes for iPad but with larger size).
Inside [UIViewController viewDidLoad] the self.view will also default to this size.
Screen rotation is only done to the top view (controller) in your hierarchy and rotation messages are forwarded through container-VCs that support this behavior (e.g. UINavigationController, UITabBarController).
If you want your view to be sized correctly, use [UIView initWithFrame:self.view.bounds] for creating a view. Insinde UIViewController you only have the chance to override the loadView Method to set the frame before viewDidLoad gets called (or you could use a different XIB for landscape). You could also hardcode the view's size by setting its frame first thing in viewDidLoad
You can use viewWillAppear to size your views before they display
You have to implement this in your settings view controller:-
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
}

iPad Layout different only on launch

Ok I have an interesting issue on an iPad application I am developing.
When the app launches in portrait mode the layout works as expected. I rotate the iPad and the rotation works fine.
When the application launches in landscape mode there is additional white space appearing and the layout does not work as expected. But when I rotate the application to portrait it rotates just fine. It also lays out fine when I rotate it back to landscape.
What could be causing this problem? The view controller in question is a view controller that contains a UINavigationController (I had to add in a header). I wonder if it is something with UINavigationController.
Your view is expecting Portrait mode upon launch. In your view Controller, you need to let it know to look for orientation, and load the corresponding view.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if(((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
(interfaceOrientation == UIInterfaceOrientationLandscapeRight))){
self.view = landscape;
}else if(((interfaceOrientation == UIInterfaceOrientationPortrait) ||
(interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))){
self.view = portrait;
}
return YES;
}
Ok so what was strange in my application is that the layout would become correct when the tab controller switched tabs back to the view that was being funky. So, I added a hack in order to switch between the tabs before the makeKeyAndVisible of the main window.
I did try your suggestion WrightsCS. The real reason it didn't work is because I'm loading UINavigationController's view in the sub view of the page, so I didn't really have control of the layout that was messing up. The top bar of the navigation controller was loading a little lower than it should have been.

UIModalPresentationFormSheet on iPad in landscape mode

I created a UIViewController view from XIB with modalPresentationStyle set to UIModalPresentationFormSheet and everything works great in portrait mode. When I switch to landscape the view gets moved upperleft (it's not centered as it should be) and most part of it is clipped.
Any ideas why this is happening and how to solve it?
Thanks
I had this problem as well. Turned out, I had the autorotate function set to Portrait for both the modal controller and the calling controller.
In iOS 7, to solve the problem of the modal view controller to appear to the left after apparition of the keyboard (problem that I have when I present an EKEventEditViewController in UIModalPresentationFormSheet, I do :
[self presentViewController:modalViewController animated:YES completion:^{
modalViewController.view.superview.center = self.view.center;
}];