在显示键盘时,使用UIModalPresentationFormSheet调整模态导航控制器的大小的正确方法是什么?

时间:2013-06-24 07:18:14

标签: ipad uinavigationcontroller modal-dialog uimodalpresentationformsh

我正在使用此代码呈现导航控制器(在呈现的视图控制器的基类中):

-(void)presentInNavigationControllerWithViewController:(UIViewController*)viewController
{
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:self];

nav.modalPresentationStyle = UIModalPresentationFormSheet;
nav.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
nav.view.autoresizingMask = UIViewAnimationTransitionNone;

[viewController presentModalViewController:nav animated:YES];


CGRect rect = self.finalRect; /*desired size +44 height*/
CGRect windowRect = [self.view.window convertRect:self.view.window.frame toView:self.view];
rect.origin.y = (windowRect.size.height-rect.size.height)/2;

nav.view.superview.frame = rect;
}

要在用户点击文字视图后调整视图大小:

// in viewDidLoad:
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(keyboardWillAppear:)
                                             name:UIKeyboardWillShowNotification object:nil];

-(void)keyboardWillAppear:(NSNotification*)notification
{
UIView *view = self.navigationController.view.superview;

view.frame =  CGRectMake(view.frame.origin.x + 200,
                         view.frame.origin.y,
                         view.frame.size.width-200,
                         view.frame.size.height);
}

在横向模式下,view.frame.size.width-200的结果是将视图的高度减少200(我是因为视图的窗口处于纵向模式?)。另一个问题是阴影滞后于导航控制器。 如果我将代码放在动画中:[UIView animateWithDuration:0.25 animations:^{,而不是阴影,则灰色矩形会落后。

这样做的正确方法是什么? (最好带动画)

0 个答案:

没有答案