UITableView goes under translucent Navigation Bar

前端 未结 14 989
一整个雨季
一整个雨季 2020-12-22 23:51

I am trying to have a transparent navigation bar in IOS 7 app. There is a full screen image in my application. I am also having a UITableView over that image. When I use the

相关标签:
14条回答
  • 2020-12-23 00:27

    I my case helped this one (modified version of Bill Chan's code):

    Objective C version:

    - (void)viewDidLayoutSubviews
    {
        [super viewDidLayoutSubviews];   
        CGRect rect = self.navigationController.navigationBar.frame;
        float y = rect.size.height + rect.origin.y;
        self.tableView.contentInset = UIEdgeInsetsMake(y, 0, 0, 0);
    }
    

    The point is that table have to be pushed down for the height of navigationBar (rect.size.height) plus status bar height (rect.origin.y);

    Swift version (also compatible with Swift 2):

    override func viewDidLayoutSubviews() {
        if let rect = self.navigationController?.navigationBar.frame {
            let y = rect.size.height + rect.origin.y
            self.tableView.contentInset = UIEdgeInsetsMake( y, 0, 0, 0)
        }
    }
    
    0 讨论(0)
  • 2020-12-23 00:27

    try to use layoutguide to fix

    var constraints = [NSLayoutConstraint]()   
    let guide = view.safeAreaLayoutGuide
                constraints.append(self.tableView.leadingAnchor.constraint(equalTo: guide.leadingAnchor))
                constraints.append(self.tableView.trailingAnchor.constraint(equalTo: guide.trailingAnchor))
                constraints.append(self.tableView.topAnchor.constraint(equalTo: guide.topAnchor))
                constraints.append(self.tableView.bottomAnchor.constraint(equalTo: guide.bottomAnchor))
    
    0 讨论(0)
提交回复
热议问题