2011-11-08 64 views
15
  1. 是否有任何方式来调整已使用故事板segue模态呈现的视图控制器的大小?ios5 - 模型视图控制器的大小与故事板

  2. 如何通过翻转过渡从此模态视图控制器中呈现另一个视图控制器?

如果我将其定义为Style = Modal,Presentation = Default,Transition = Flip Horizo​​ntal,它看起来很奇怪(背景是白色的)。

Thx!

+3

注意,你几乎总是需要一个modalViewController拿整个屏幕。这是因为在modalViewController出现后,“在”modalViewController下的viewController被移除。因此,如果你试图用你的modalViewController覆盖屏幕的一半,其目的是让其他viewController显示“underneath”,这是行不通的。它会显示白色。我通过添加视图作为父视图的子视图来完成此功能。 – bearMountain

+0

您的评论在框架行为方面可能是正确的,但是您的“想要”应该由您的应用的用户体验决定,以及对用户最合适,而不是UI框架的底层交互。您的用户体验可能决定在自定义对话框中显示您的模态UI,在这种情况下,您仍然需要查看对话框后面的内容。通过根据需要手动添加/删除对话框子视图(变暗,对话框内容),自定义的渐变和展开渐变可轻松处理此操作,而无需删除先前控制器的视图。 – Marchy

+0

http:// stackoverflow上有一个工作解决方案。com/questions/25250510/set-size-of-iphone-view-controller/25251507#25251507 –

回答

34

是的。在界面构建器中选择视图控制器,并在属性检查器中设置Size以自由形式(从推断)。然后选择视图并将其测量值设置为您需要的值。一个重要的注意点是在视图控制器中取消选中从NIB调整视图大小,否则视图将再次变为全屏。

不确定第二个问题,如果背景是唯一的问题,你不能只是设置颜色?

希望这会有所帮助。

+4

这不起作用,至少在我的情况下,我的确如你所说。任何想法?谢谢。 – Ricardo

+8

+1提到调整大小视图从NIB复选框,我永远不会发现,否则。 – DonnaLea

+0

你是男人!非常感谢! –

1

我试图做同样的,在故事板我ModalView较小,但在模拟器它涵盖了所有的屏幕...

我觉得这不能在iPhone上完成了...(我在iPad上做了一个简单的测试,模态视图起作用)。

我会尝试iPhone的半透明视图,不会使用模态视图。

希望这会有所帮助。

5

您可以使用自定义UIStoryboardSegue调整模态显示视图的大小。在故事板中,将segue设置为Custom而不是Modal。在Segue类中,给它一个你的UIStoryboardSegue覆盖的名字。

要覆盖UIStoryboardSegue,您在.h文件中不需要任何东西。它会出现这样的事情:

MyStoryboardSegue.h:

#import <UIKit/UIKit.h> 
@interface MyStoryboardSegue : UIStoryboardSegue 
@end 

在MyStoryboardSegue.m,代码为:

#import "MyStoryboardSegue.h" 

@implementation MyStoryboardSegue 


- (void)perform 
{ 
    id sourceController = self.sourceViewController; 
    id destinationController = self.destinationViewController; 
    UIView *destinationView = [destinationController view]; 
    CGFloat x, y, w, h; 

    [destinationController setModalPresentationStyle:UIModalPresentationFormSheet]; 
    [destinationController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve]; 
    [sourceController presentViewController:destinationController animated:YES completion:nil]; 

/* 
You have to present the view first, and then resize it. That's because, 
as far as I can tell, when you present your view modally, a new view is created 
that covers the screen in a black semi-transparent mask to give the shadow effect, 
and a container view is placed in the middle of this view that in turn holds the 
view you are presenting. Your view automatically resizes to the size of this 
container view, so that's the view you need to resize to make your view controller 
appear the size you desire. You must present your modal view first 
because until you do, the container view doesn't exist. The following code 
resizes the container view (which is now your modal view's superview) and then 
resets the position of the container view to the center of the source view that 
is presenting the modal view so everything looks nice and centered. 
*/ 
    x = destinationView.superview.frame.origin.x; 
    y = destinationView.superview.frame.origin.y; 
    w = 400; // Your desired modal view width 
    h = 400; // Your desired modal view height 
    destinationView.superview.frame = CGRectMake(x, y, w, h); 
    destinationView.superview.center = [[sourceController view] center]; 
} 

@end 
+0

我已经在UINavigationController中的Xcode 5中完成了这项工作(如果有的话),它似乎不工作,除非我失去了一些东西...... –

相关问题