我正在向导航控制器呈现这段代码(在呈现的视图控制器的基类中):
-(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:^{
,而不是阴影,灰色矩形会落后。
这样做的正确方法是什么?(最好有动画)