ios5 - 带故事板的模态视图控制器的大小

时间:2011-11-08 15:25:37

标签: ios uiviewcontroller ios5 modalviewcontroller storyboard

  1. 有没有办法调整使用故事板segue以模态方式呈现的视图控制器?

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

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

    THX!

3 个答案:

答案 0 :(得分:34)

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

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

希望这有帮助。

答案 1 :(得分:5)

您可以使用自定义UIStoryboardSegue调整模式呈现的视图的大小。在故事板中,将segue设置为Custom而不是Modal。在Segue Class中,给它命名为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

答案 2 :(得分:1)

我正在尝试做同样的事情,在storyBoard中我的ModalView更小,但在模拟器中它覆盖了所有屏幕......

我认为这不可能在iPhone中完成......(我在iPad上做了一个简单的测试,模态视图也有效。)

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

希望这有帮助。