问题
I understand there is this question: Adding subview leaves gap between subview and navigation bar
However, there is no answer, and I do my method a different way, so that might make it a bit different. Anyways, I as well have a gap between the navigation bar and subview when I add a subview to my navigation controller, which also has a tab bar controller. I am using storyboards. I am adding the subview using UIViewController.view
type via storyboard id.
My code:
[self.view addSubview:[[self.storyboard instantiateViewControllerWithIdentifier:@"View"] view]];
This works, and adds the view, but with the gap above it. Any suggestions? Thanks.
回答1:
On your 'View' view controller defined in Storyboard, set the 'Resize View From NIB' property to unticked (this is ticked by default). This cured the gap problem for me.
回答2:
I solved it by setting the translucent
property of UINavigationController
to NO
. Add the following line in viewDidLoad
self.navigationController.navigationBar.translucent = NO;
来源:https://stackoverflow.com/questions/15801365/gap-between-navigation-bar-and-subview-ios