Presenting a view controller of custom size with n

2019-06-10 06:52发布

问题:

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:

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

回答1:

Just putting transparent overlay on the view controller and present it, sothat it looks like as what you actually want...

Also refer the following link,

Show modal view controller with custom frame in iPad

How to present a modal view controller with custom size in center?

iPad custom size of modal view controller

http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html