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:

4

3 回答 3

5

使用 iOS7 的诀窍是将 modalTransitionStyle 设置为 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

于 2013-12-19T17:30:35.200 回答
1

最后代码是下一个:

// 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);
}

+10 和 -10 是因为默认情况下,模式的 NavigationController 不在屏幕顶部。

这是......一个糟糕的解决方案:SS但有效......虽然如果有人有建议会很高兴知道。

如果我需要为两个方向包含相同的中心,则可能超级视图的方向不是预期的方向。

在这个解决方案中,当我关闭纵向模式视图时,至少在 iPad 模拟器上,它会自动旋转到纵向模式......

最终的解决方案是在主控制器 UITabBar 上执行 presentModalViewController,并更新要在其上执行的解除方法。

[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);
}

最后!!!!

谢谢,

伊万

于 2011-09-22T23:27:54.783 回答
0

在 iOS 7 中,为了解决模式视图控制器在键盘出现后出现在左侧的问题(当我在 UIModalPresentationFormSheet 中呈现 EKEventEditViewController 时遇到的问题,我这样做:

[self presentViewController:modalViewController animated:YES completion:^{
    modalViewController.view.superview.center = self.view.center;
}];
于 2014-09-17T13:50:33.607 回答