How iOS UITableView under NavigationBar?

后端 未结 5 1275
渐次进展
渐次进展 2021-01-11 15:17

I have set

NavigationController.NavigationBar.Translucent = true;

Then add table and set frame to RootView Frame, and:

             


        
相关标签:
5条回答
  • 2021-01-11 15:35

    This worked for me

    let yOffset = UIApplication.shared.statusBarFrame.height + self.navigationController!.navigationBar.frame.size.height
    tableView.contentInset = UIEdgeInsetsMake(yOffset, 0, 0, 0)
    
    0 讨论(0)
  • 2021-01-11 15:37

    Try this:

        if([self respondsToSelector:@selector(edgesForExtendedLayout)])
        {
           self.edgesForExtendedLayout = UIRectEdgeNone;
           self.automaticallyAdjustsScrollViewInsets = NO;
        }
    
    0 讨论(0)
  • 2021-01-11 15:52

    Just put

    navigationBar.translucent = NO; you problem will solve :)

    Other option is,,

    Put following code.

    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
    
        if([self respondsToSelector:@selector(edgesForExtendedLayout)])
            [self setEdgesForExtendedLayout:UIRectEdgeBottom];
    }
    

    Another option is ..

    Why does UIViewController extend under UINavigationBar, while UITableViewController doesn't?

    0 讨论(0)
  • 2021-01-11 15:53

    I solved task with this simple code:

    table.ScrollIndicatorInsets = new UIEdgeInsets(64, 0, 0, 0);
    
    0 讨论(0)
  • 2021-01-11 15:53

    Solutions that introduce a magic constant don't scale most of the time. For example, if the next iPhone introduces a different navigation bar height we'll have to update our code.

    Fortunately, Apple provided us cleaner ways of overcoming this issue, for example topLayoutGuide:

    The topLayoutGuide property comes into play when a view controller is frontmost onscreen. It indicates the highest vertical extent for content that you don't want to appear behind a translucent or transparent UIKit bar (such as a status or navigation bar)

    Programmatically you can achieve with the following code snippet (the same can be achieved via IB too):

    override func viewDidLoad() {
      super.viewDidLoad()
    
      automaticallyAdjustsScrollViewInsets = false
      tableView.translatesAutoresizingMaskIntoConstraints = false
      NSLayoutConstraint.activate([
        tableView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
        tableView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
        tableView.topAnchor.constraint(equalTo: 
           topLayoutGuide.bottomAnchor),
        tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
      ])
    }
    

    Note: topLayoutGuide is deprecated on iOS 11, we should use the safeAreaLayoutGuide property of UIView instead.

    0 讨论(0)
提交回复
热议问题