通过导航呈现自定义尺寸的视图控制器 [英] Presenting a view controller of custom size with navigation

查看:115
本文介绍了通过导航呈现自定义尺寸的视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提供一个自定义大小的视图控制器说(500,500)。我尝试用下面的代码做到这一点,如果我单独呈现视图控制器,但是当我将视图控制器放在导航控制器(我想做)时,它可以正常使用半透明浅灰色背景,有黑色背景出现了,我不想要这个,我想要灰色的。



我在这个问题的帮助下做了以下代码:





如何在中心呈现自定义尺寸的模态视图控制器?



板模式视图控制器的自定义尺寸



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


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)

解决方案

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

这篇关于通过导航呈现自定义尺寸的视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆