View controller in terms of complexity when presented as a form sheet

I am trying to present a view controller with its presentation style set to form a sheet. However, when the view controller appears , it is located to the right of the screen, and not in the center. I do not know why this is happening or what I should do. All 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

+5
source share
1 answer

It seems that whenever I delete the last two lines, I get what I assume is the behavior 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 these two lines, but without them the point of view is centered.

+1
source

All Articles