iOS 7 Custom TableView Is Under TabBar

2019-01-21 17:20发布

问题:

Im trying port my app to iOS7, but my custom TableViewController is showing the last row (cell) under the TabBar :(

Im searching a lot for it, but i dont find any solution. Can anyone help me?

My Custom Table View class

The error is shown in the blow screenshot (only is showing a part of last product because im draging to up to show the hidden product under the tabbar):

Thanks.

回答1:

I found the answer to your question on another post, answered by dariaa, here:

Tab Bar covers TableView cells in iOS7

It worked great for me.

Please no credit for me, because I'm not the original guy who solved it.

In your custom TableViewController, add these two lines under [super viewDidLoad]:

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.edgesForExtendedLayout = UIRectEdgeAll;
    self.tableView.contentInset = UIEdgeInsetsMake(0., 0., CGRectGetHeight(self.tabBarController.tabBar.frame), 0); 
} 


回答2:

I've got the same problem and solved it using storyboard. At Tab Bar Controller, go to attribute inspector, Simulated Metrics, and set the Bottom Bar to Opaque Tab Bar. That's it! See image bellow for description.

Saudações! (Greetings!)



回答3:

2 lines in viewDidLoad and that's it !

self.edgesForExtendedLayout = UIRectEdgeAll;
self.tableview.contentInset = UIEdgeInsetsMake(0.0f, 0.0f, CGRectGetHeight(self.tabBarController.tabBar.frame), 0.0f);


回答4:

My friends, I cannot tell you how badly I struggled from this. Not a single re-configuration of Story Board never helped me. The issue was exactly like in Original Post, I've managed to fix it using:

for swift 3

self.edgesForExtendedLayout = []

for objective-c

self.edgesForExtendedLayout = NO;


回答5:

In iOS 7 viewController uses full height. There is a property introduced as

self.automaticallyAdjustsScrollViewInsets = NO;

set it to no. then check, or set UIEdgeInset if is not set right after it.

UIEdgeInsetsMake(top, left, bottom, right)

See here https://developer.apple.com/library/ios/documentation/userexperience/conceptual/TransitionGuide/AppearanceCustomization.html

Edit: try also this

self.edgesForExtendedLayout = UIRectEdgeNone;


回答6:

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:

  1. Make sure "Adjust Scroll View Insets" is checked.
  2. Make sure that the tableView is the first subview in the view Hierarchy. (Move it upwards above all other elements)


回答7:

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:.



回答8:

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.



回答9:

Try the following:

 if ([self respondsToSelector:@selector(edgesForExtendedLayout)])

 self.edgesForExtendedLayout = UIRectEdgeBottom;


回答10:

I've got the same problem. One solution to it is to make the ToolBar not Translucent. Here's how to do it:

  • First select the tool bar from the document viewer like here
  • Then uncheck Translucent like here

Hope this helps.

Thanks.



回答11:

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.



回答12:

I solved my problem now, changing my BaseTableViewController to inherit from UIViewController to UITableViewController.

But using a TableView inside a UIViewController is not solved :(

Thanks.



回答13:

maybe is not a right answer, also for that reason I post this answer so you can tell me if this answer could be a possible solution.

In my case, I like the translucent effect, so I have added a footer in the table and I have modified the scrollIndicators.

- (void)viewDidLoad
{
    // Do any additional setup after loading the view.
    [super viewDidLoad];
    UIView *footer = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.agendaItemsTable.frame.size.width, self.tabBarController.tabBar.frame.size.height)];
    self.agendaItemsTable.tableFooterView = footer;
    self.agendaItemsTable.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, self.tabBarController.tabBar.frame.size.height, 0);

}

What do you think?



回答14:

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!



回答15:

For those like xarly who want the translucent effect, and for an Autolayout solution (without setting frames), see my answer here https://stackoverflow.com/a/26419986/1158074



回答16:

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!