0

I have button in main view,when i click on main view button model view Mv1 is open.Mv1 model view width and height is 730 and 620.in portrait mode Mv1 model view show center in main view but in landscape mode Mv1 model view show center horizontally but does not show center vertically in main view.

main view button click coding:-

Mv1 *Mv1obj = [[Mv1 alloc]initWithNibName:@"Mv1" bundle:nil];
UINavigationController*nav[[UINavigationControlleralloc]initWithRootViewController:Mv1obj];
nav.modalPresentationStyle=UIModalPresentationFormSheet;
nav.modalTransitionStyle=UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:nav animated:YES];
nav.view.superview.frame = CGRectMake(0, 0,730,620);
nav.view.superview.center = self.view.center;

if know please replay,thanks in advance.

Gauging
  • 705
  • 1
  • 6
  • 8

1 Answers1

0

The issue here is that you need to account for orientation when setting the center, so replace the line:

nav.view.superview.center = self.view.center;

with something like

UIDeviceOrientation orientation = ([[UIDevice currentDevice] orientation]);
const CGPoint centerPortait = self.view.center;
const CGPoint centerLandscape = CGPointMake(centerPortait.y, centerPortait.x);
const CGPoint center = (orientation == UIDeviceOrientationPortrait) ? centerPortait : centerLandscape;
nav.view.superview.center = center;

this will correctly center the modal view.

jstevenco
  • 2,913
  • 2
  • 25
  • 36