PresentModalViewController与一些框架

时间:2012-06-27 15:45:11

标签: iphone ios presentmodalviewcontroller uimodalpresentationstyle

我想呈现一个带有小框架并位于视图中心的modalViewController。

这可能吗?

即使我将一些框架设置为viewController对象,presentModelViewController也会以全屏模式显示该视图。

另外,我使用modalPresentationStyle作为UIModalPresentationFormSheet。我希望框架比这更小。

怎么做?

3 个答案:

答案 0 :(得分:5)

无法呈现具有较小帧尺寸的模态视图控制器。

您可以尝试做的是将模态视图控制器的背景设置为透明,然后在中心添加较小尺寸的视图(或者您希望看到它的位置)。

答案 1 :(得分:1)

呈现模态视图将覆盖整个视图,如果您不想覆盖整个视图,则应自行创建视图,将其作为子视图添加到当前视图,然后自行设置其过渡动画。它不会是一个单独的viewController,因为你仍然在原始视图的范围内操作。

答案 2 :(得分:0)

是。有可能的。请按照以下步骤操作:

- (void)viewDidLoad {
     [super viewDidLoad];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShown:) name:UIKeyboardWillShowNotification object:nil];
     CGRect rect = CGRectMake(242, 60, 540, 312);
     self.controller.view.superview.frame = [self.view convertRect:rect toView:self.controller.view.superview.superview];
}

- (void)keyboardWillShown:(NSNotification*)aNotification {
     CGRect rect = CGRectMake(242, 60, 540, 312);
     self.controller.view.superview.frame = [self.view convertRect:rect toView:self.controller.view.superview.superview];
}

您必须在控制器设置之后(在viewDidLoad方法结束之前)设置当前控制器的帧。

这里我考虑过iPad目前的视图控制器框架。