Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fatuhoku/472a78f6dbbd101a178f to your computer and use it in GitHub Desktop.
Save fatuhoku/472a78f6dbbd101a178f to your computer and use it in GitHub Desktop.
Make popover resize according to the preferredSizes of ViewControllers
// Conform to UINavigationControllerDelegate and then implement this:
// Especially if the topViewController is a RBStoryboardLink or something.
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
// NB: Using navigationController.preferredContentSize would be better here, but it doesn't reset properly when navigating back so we manually add on the height of the navbar instead.
CGSize size = viewController.preferredContentSize;
CGFloat navbarHeight = navigationController.navigationBar.frame.size.height;
<topViewController>.preferredContentSize = CGSizeMake(size.width, size.height + navbarHeight);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment