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

发布于 2024-12-14 13:22:06 字数 220 浏览 5 评论 0原文

  1. 是否有任何方法可以调整已使用故事板segue以模态方式呈现的视图控制器的大小?

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

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

谢谢!

  1. is there any way to resize a View Controller that has been presented modally using a storyboard segue?

  2. how do I present another View Controller from this modal view controller with a flip transition?

If I define it as Style=Modal, Presentation=Default, Transition=Flip Horizontal it just looks weird (background is white).

Thx!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不喜欢何必死缠烂打 2024-12-21 13:22:06

是的。在界面生成器中选择视图控制器,然后在属性检查器中将“大小”设置为自由形式(根据推断)。然后选择视图并将其测量值设置为您需要的任何值。需要注意的重要一点是在视图控制器中取消选中 Resize View From NIB,否则视图将再次变为全屏。

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

希望这有帮助。

Yes. In interface builder select the view controller and in the attribute inspector set Size to freeform (from inferred). Then select the view and set its measurements to whatever you require. An important point to note is uncheck Resize View From NIB in the view controller otherwise the view becomes full screen again.

Not sure about the second question if the background is the only problem can't you just set the colour?

Hope this helps.

看透却不说透 2024-12-21 13:22:06

您可以使用自定义 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

You can resize a modally-presented view with a custom UIStoryboardSegue. In the storyboard, set the segue to Custom instead of Modal. In the Segue Class, give it the name of your UIStoryboardSegue override.

To override UIStoryboardSegue, you won't need anything in your .h file. It will appear as something like this:

MyStoryboardSegue.h:

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

In MyStoryboardSegue.m, the code would be:

#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
眼泪淡了忧伤 2024-12-21 13:22:06

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

我认为这不能在iPhone中完成...(我在iPad和模态视图有效)。

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

希望这有帮助。

I'm trying to do the same, and in storyBoard my ModalView is smaller , but in simulator it covers all screen...

I think this cannot be done in iPhone... (I've made a simple test in iPad and the modal view worked).

I'll try a semi-transparent view for iPhone and won't use a Modal View.

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文