Presenting a view controller of custom size with navigation

☆樱花仙子☆ 提交于 2019-12-08 13:29:00

问题


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



来源:https://stackoverflow.com/questions/15802633/presenting-a-view-controller-of-custom-size-with-navigation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!