有没有办法调整使用故事板Segue模式呈现的视图控制器的大小?
如何使用翻转过渡从此模态视图控制器呈现另一个视图控制器?
如果我将其定义为Style=Modal,Presentation=Default,Transition=Flip Horizontal,则它看起来很奇怪(背景是白色)。
谢谢!
有没有办法调整使用故事板Segue模式呈现的视图控制器的大小?
如何使用翻转过渡从此模态视图控制器呈现另一个视图控制器?
如果我将其定义为Style=Modal,Presentation=Default,Transition=Flip Horizontal,则它看起来很奇怪(背景是白色)。
谢谢!
是的。在接口构建器中,选择视图控制器,在属性检查器中将大小设置为自由格式(从推断中)。然后选择视图并将其测量值设置为所需值。一个重要的注意点是在视图控制器中取消选中“从NIB调整视图大小”,否则视图将再次变成全屏。
如果背景颜色是唯一的问题,不确定第二个问题,您可以只是设置背景颜色吗?
希望这可以帮助您。
您可以使用自定义的UIStoryboardSegue调整模态呈现视图的大小。在Storyboard中,将segue设置为Custom而不是Modal。在Segue Class中,将其命名为您的UIStoryboardSegue覆盖。
要覆盖UIStoryboardSegue,您不需要在.h文件中添加任何内容。它会出现如下形式:
MyStoryboardSegue.h:
#import <UIKit/UIKit.h>
@interface MyStoryboardSegue : UIStoryboardSegue
@end
#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
我也在尝试同样的事情,在storyBoard中我的ModalView比较小,但是在模拟器中它覆盖了整个屏幕...
我认为这在iPhone上无法实现...(我在iPad上进行了简单的测试,modal视图可以正常工作)。
我将尝试在iPhone上使用半透明视图,而不是使用Modal View。
希望这能有所帮助。