3

We've the next problem in our iPad version.

I've a NavigationController inside a UITabBar. I want to show a Form with a look&feel similar than the e-Mail form.

I use the same code to show a model centered:

// View to be displayed in the modal
AdhocViewController *controller = [[AdhocViewController alloc] initWithNibName:@"AdhocViewController" bundle:[NSBundle mainBundle]];
controller.caller = self;

// The form will need a navigation bar to cancel or save the form
UINavigationController *modalViewNavController = [[UINavigationController alloc] 
                                               initWithRootViewController:controller];

// Configurate the modal presentation and transition
modalViewNavController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
modalViewNavController.modalPresentationStyle = UIModalPresentationFormSheet;

// Show the new view
[self presentModalViewController:modalViewNavController animated:YES];

This code works perfectly on portrait mode, but on landscape the view appears partially out of the screen ... and I didn't found yet the way to solve it.

I test some of the solutions I found here ...

And try to add the next lines after preset the model view to resize it, but doesn't work it out

controller.view.superview.frame = CGRectMake(0, 0, 600, 700);
controller.view.superview.center = self.view.center;

Any suggestion?

Thanks,

Ivan

References in StackOverflow:

Community
  • 1
  • 1
Iván Peralta
  • 851
  • 1
  • 9
  • 25
  • Try this answer: http://stackoverflow.com/questions/4272718/modal-view-using-uimodalpresentationformsheet-appears-offscreen/4273720#4273720 –  Sep 22 '11 at 15:43
  • I'll try ... for the moment, I fix the portrait mode - (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{ return (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)); } – Iván Peralta Sep 22 '11 at 16:10
  • Karenina, I already found it and checked it .. but doesn't success ... could you share exactly the code do you use? Thank you – Iván Peralta Sep 22 '11 at 16:12
  • All that answer says is make sure you return the same value from shouldAutorotate from both the view controller _doing_ the presenting _and_ the view controller _being_ presented. It doesn't matter what the value is as long as all view controllers agree. –  Sep 22 '11 at 16:32
  • I'm sure if i'm wrong ... but with this method on the modal ... should be enough. not? - (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrient‌​ation{ return [caller shouldAutorotateToInterfaceOrientation:toInterfaceOrientation]; } – Iván Peralta Sep 22 '11 at 16:52
  • Not sure. Try hard-coding both VCs to YES as an experiment. It's possible that `caller` is nil (not yet set) the _first_ time that method is called in the pop up vc. –  Sep 22 '11 at 17:16

3 Answers3

5

With iOS7 the trick is to set the modalTransitionStyle to UIModalTransitionCrossDissolve.

UIViewController *viewController = [[UIViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];

navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
navigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

[self presentViewController:navigationController animated:YES completion:nil];
navigationController.view.superview.frame = CGRectMake(0, 0, 800, 544);
navigationController.view.superview.center = self.view.center;

https://coderwall.com/p/vebqaq

caoimghgin
  • 629
  • 1
  • 9
  • 15
1

Finally the code was the next:

// Remove the modalTransitionStyle to enable the default behaviour and change to PageSheet
modalViewNavController.modalPresentationStyle = UIModalPresentationPageSheet;
// Present the modal view and adapt the center depending of the orientation
[self presentModalViewController:modalViewNavController animated:YES];

UIDeviceOrientation _orientation = [controller interfaceOrientation];
if (UIDeviceOrientationIsPortrait(_orientation)){
    modalViewNavController.view.superview.center = CGPointMake(768/2, 1024/2 + 10);
} else {
    modalViewNavController.view.superview.center = CGPointMake(768/2 - 10, 1024/2);
}

The +10 and -10 is because by deafult the NavigationController of the modal was out of the screen on top.

It is ... a crappy solution :SS but works ... Although if anybody have suggestions would be nice to know.

Seams that if I need to include the same center for both orientation, maybe the orientation of the superview is not the expected one.

In this solution, when I dissmiss the modal view on Portrait orientation, at least on the iPad simulator, it rotate to portrait mode automatically ...

The final solution was to execute the presentModalViewController over the main controller, the UITabBar, and update the dismiss method to be executed also over it.

[tabbar presentModalViewController:modalViewNavController animated:YES];

UIDeviceOrientation _orientation = [controller interfaceOrientation];
if (UIDeviceOrientationIsPortrait(_orientation)){
    modalViewNavController.view.superview.center = CGPointMake(768/2, 1024/2 + 10);
} else {
    modalViewNavController.view.superview.center = CGPointMake(1024/2, 768/2 + 10);
}

Finally!!!!

Thank you,

Iván

ThomasCle
  • 6,792
  • 7
  • 41
  • 81
Iván Peralta
  • 851
  • 1
  • 9
  • 25
0

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;
}];
Jon - LBAB
  • 928
  • 11
  • 20