I'm presenting the navigation controller with this code (in the base class of the view controller being presented):

-(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;
}

To resize the view afterwards when the user clicks the text view:

// 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);
}

In landscape mode, the result of view.frame.size.width-200 is decreasing the view's height by 200 (I'm because because the view's window is in portrait mode?). Another problem is that the shadow lags behind the navigation controller. If I put the code in a animation : [UIView animateWithDuration:0.25 animations:^{, instead of a shadow, a gray rectangle lags behind instead.

What's the correct way of doing this ? (preferably with animation)

0

There are 0 best solutions below