0

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

Community
  • 1
  • 1
Satheesh
  • 10,998
  • 6
  • 50
  • 93

1 Answers1

2

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

Community
  • 1
  • 1
Venk
  • 5,949
  • 9
  • 41
  • 52
  • Yeah i get you, but the thing is that I am getting a transparent view by default if I present a ViewController object and a black one when I am presenting a NavigaitonContoller with ViewController in it. Why is that so?? – Satheesh Apr 04 '13 at 06:39
  • can you put the screenshot – Venk Apr 04 '13 at 06:47
  • kindly try like this `[self.navigationControler presentModalViewController:nav animated:YES];` instead of `[self.window.rootViewController presentModalViewController:nav animated:YES];` – Venk Apr 04 '13 at 07:01
  • I am doing all this universally so this controller can come up in any scree with a gesture. So i cannot user self.navigationController may be I would try self.window.rootViewController.navigationController. – Satheesh Apr 04 '13 at 07:05
  • which backgroundcolor?? window or the VC? – Satheesh Apr 04 '13 at 07:15