Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difficulty centering view controller when presented as form sheet

I'm trying to present a view controller with its presentation style set to form sheet. However, when the view controller appears, it is positioned to the right of the screen, not in the center. I am not sure why this is happening, or what I should do. All of these coordinates are correct!

CGSize size = CGSizeMake(650, 550);

//custom init for ViewController so I can position stuff correctly
ViewController *vc = [[ViewController alloc] initWithSize:size];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];

nav.modalPresentationStyle = UIModalPresentationFormSheet;
nav.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

[self presentModalViewController:nav animated:YES];

nav.view.superview.frame = CGRectMake(0, 0, size.width, size.height);
nav.view.superview.center = self.view.center;

enter image description here

like image 333
Jack Humphries Avatar asked Nov 13 '22 09:11

Jack Humphries


1 Answers

It seems that whenever I remove the last two lines, I get what I assume to be the behavior that you are looking for.

CGSize size = CGSizeMake(650, 550);

//custom init for ViewController so I can position stuff correctly
ViewController *vc = [[ViewController alloc] initWithSize:size];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];

nav.modalPresentationStyle = UIModalPresentationFormSheet;
nav.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

[self presentModalViewController:nav animated:YES];

I'm not sure exactly what you were trying to do with those two lines, but without them the view is centered.

like image 147
Jsdodgers Avatar answered Nov 15 '22 07:11

Jsdodgers