Im trying port my app to iOS7
, but my custom TableViewController
is showing the last row (cell) under the TabBar
:(
Im searchi
I had a similar problem with collection view. Changing the collection view frame and content inset below fixed it for me...
guard let cv = collectionView,
let tabBar = tabBarController?.tabBar else { return }
// Resize collection view for tab bar
let adjustedFrame = CGRect(origin: cv.frame.origin,
size: CGSize(width: cv.frame.width, height: cv.frame.height - tabBar.frame.height))
cv.frame = adjustedFrame
// Adjust content inset for tab bar
let adjustedContentInsets = UIEdgeInsetsMake(0, 0, tabBar.frame.height, 0)
cv.contentInset = adjustedContentInsets
cv.scrollIndicatorInsets = adjustedContentInsets
Good luck!
UIViewController has two new properties to assist you : topLayoutGuide
and bottomLayoutGuide
. They return the height of the parent view controller's controls you need to avoid. In this case, bottomLayoutGuide
will return the offset of the tab bar.
Your custom view controller is probably overriding a method and not invoking super
's implementation where this would be done for you. I am guessing you are installing AutoLayout constraints or setting a view's frame manually to fill the view. You just need to include the value from [bottomLayoutGuide length]
to your layout calculation. If you support rotation, you should update that value in willAnimateRotationToInterfaceOrientation:duration:
.
I had the same problem, and the up-voted answers did not solve it. See my answer to a similar question, Tab Bar covers TableView cells in iOS7.
I solved the issue by manually setting the table view's frame in the table view controller's viewWillAppear:
method to the height of the screen - (status bar height + nav bar height + tab bar height).
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// Adjust height of tableview (does not resize correctly in iOS 7)
CGRect tableViewFrame = self.tableView.frame;
tableViewFrame.size.height = [self heightForTableView];
self.tableView.frame = tableViewFrame;
}
- (CGFloat)heightForTableView
{
return CGRectGetHeight([[UIScreen mainScreen] bounds]) -
(CGRectGetHeight([[UIApplication sharedApplication] statusBarFrame]) +
CGRectGetHeight(self.navigationController.navigationBar.frame) +
CGRectGetHeight(self.tabBarController.tabBar.frame));
}
If anyone finds a better solution to this problem, please share!
UINavigationController
and UITabBarController
both have a transparency flag that can be set programmatically or in the storyboard.
The UINavigationController
also has two flags that control if the content extends under the top or bottom bar. Again you can set them programmatically or in the storyboard. This will apply to all subviews.
Each UIViewController
can set its own preference in code. The property is called edgesForExtendedLayout
and you can set up all combinations.
Using those properties will allow AutoLayout and Springs'n'Struts to adjust the views the way you want them regardless of the device.
There are a lot more new properties in UIViewController
that you will want to have a look at.
The root cause of this problem is that automaticallyAdjustsScrollViewInsets
is effective only on the First scroll view in your VC's view Hierarchy. It is not documented by Apple, but it is the only way the VC will detect the scroll view needing to be modified unless you're using a UITableViewController.
So in order to fix your issue without manually adjusting the insets, do this:
The problem was masked using:
-(void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 112, 0);
}
But it doesn't solve, because on each iPhone and on each app tableview i have a different space on bottom.
So this is a poor solution.
I dont know a way to solve it.