Landscape mode with modal view - objective-c

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?

Related

Presented View Controller from custom modal presentation not autorotating in iOS7 -(BOOL)shouldAutorotate not being called properly

I have a view controller that I am presenting with a Custom Modal Presentation
myViewController.modalPresentationStyle = UIModalPresentationCustom;
myViewController.transitioningDelegate = self;
[self presentViewController:myViewController animated:YES completion:nil];
Works as expected but for some reason (in iOS7) the presented view controller is not autorotating when the device orientation changes. Apparently the (presented view controller's) method:
- (BOOL)shouldAutorotate {
return YES;
}
is not being called in iOS7 when the device orientation changes. It's only called once when it is first shown. When I run it on iOS8 it works fine and shouldAutorotate is being called properly. Its strange because it can only be presented in Portrait. If I try to present the view in landscape it does not work. I have checked all my parent view controllers and they are all setup correctly and I have all orientations set in my plist and my app delegate methods. Any body have any ideas as to why this works in iOS8 but not iOS7?

How comes this UIViewController is always displayed in Portrait Mode?

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.

Force rotation of a UIViewController in a NavigationController in a TabbarController

I've got my View hierarchy set up like this.
UITabBarController
|
UINavigationController
| |
| UIViewController
|
UINavigationController
|
UIViewController
The thing is that I have a ViewController that is only shown in Portrait, as soon as I turn the device to landscape another ViewController is being pushed on top, that is working as intended so far.
What I want now is that as soon as I push the back button on the newly popped ViewController that the old ViewController is being forced to Portrait, even though the Device is still in Landscape.
I have tried it with transitions, but then the other views are getting screwed and don't properly recognize there orientation anymore leading to a mess of displaced views.
The only thing that worked for me was using
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
in my ViewController and presenting it with presentModalViewController.
This forces the View to stay in landscape.
Not exactly what I wanted, but it worked out.
Try adding this to your original view controller:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) return YES;
return NO;
}
This should force it to only display in portrait orientation.
The code below will force the view into landscape mode, but only if the parent view controller supports landscape mode.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
If the parent view controller of the view you want to force into landscape mode is portrait only, you'll have to create a new new navigation controller. The easiest way to do that is just presenting the forced-landscape view controller in a modal view. So use presentModalViewController instead of pushViewController.

Dismissing modal view makes main view rotate

I have a main view that I rotate to landscape using
-(void)viewDidLoad {
self.view.transform = CGAffineTransformMakeRotation(90);
self.view.bounds = CGRectMake(-0.0, 0.0, 480.0, 320.0);
It works great. The problem is that this view can call a modal view, and when I dismiss the modal view the main view returns to portrait. Any ideas why this happens and how can I fix it?
Are you overriding shouldAutorotateToInterfaceOrientation: in your main view and returning YES for any orientation? If not, your main view thinks that it can only support portrait mode, and will autorotate back to portrait whenever it comes to the front.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
return YES;
}

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.