Presenting a view controller of custom size with n

2019-06-10 06:45发布

I want to present a view controller of custom size say (500,500). I try to do that with the below code, it works fine with a semi transparent light gray background if I present the view controller alone but when i put the view controller in a navigation controller (which I want to do) there is a black background that comes up, I dont want this and I want the gray one.

I did the following code with the help of this question:

iOS -- how do you control the size of a modal view controller?

MyViewController *vc=[[MyViewController alloc]initWithNibName:@"MyViewController" bundle:nil];

UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:vc];

nav.modalPresentationStyle=UIModalPresentationPageSheet;

[self.window.rootViewController presentModalViewController:nav animated:YES];

CGRect r = CGRectMake(self.window.rootViewController.view.bounds.size.width/2 - 250,
                              self.window.rootViewController.view.bounds.size.height/2 - 250,
                              500, 500);
r = [self.window.rootViewController.view convertRect:r toView:vc.view.superview.superview];
  vc.view.superview.superview.frame = r;

Any guess, what I am missing here?? Or is there a easy way to present a custom size VC with navigation??

With navigation:

enter image description here

Without navigation: (i am using a dark background, so it may appear like it is black but it is not) enter image description here

登录 后发表回答