2017-10-24 37 views

答えて

1

プログラムにより、SafeAreaLayoutの下部アンカーとテーブルビューの下部にアンカーを設定します。

ここにサンプル/テストコードがあり、インタフェース要素に対して安全な領域のレイアウトをプログラムで設定する方法を示します。あなたがsafeArea時間に制約を設定iOS11 &でsafeAreaLayoutGuideを使用する必要があります

+0

のために仕事をして私は私にいくつかの時間を与えて、それ確か –

+1

のObjective Cのバージョンを持つことができ、あなたのOBJ-Cのコードを提供します。テーブルビューの変数名を教えてください。 – Krunal

+0

'self.tableView' –

1

:ここ

if #available(iOS 11, *) { 
    let guide = view.safeAreaLayoutGuide 
    NSLayoutConstraint.activate([ 
    table.topAnchor.constraintEqualToSystemSpacingBelow(guide.topAnchor, multiplier: 1.0), 
    guide.bottomAnchor.constraintEqualToSystemSpacingBelow(table.bottomAnchor, multiplier: 1.0) 
    ]) 

} else { 
    let standardSpacing: CGFloat = 8.0 
    NSLayoutConstraint.activate([ 
    table.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor, constant: 0), 
    bottomLayoutGuide.topAnchor.constraint(equalTo: table.bottomAnchor, constant: 0) 
    ]) 
} 

は便利な参照(答)ですあなたのコンテンツはクリップされません。 UITableViewに制約を設定するため

-

にObjC

self.tableView.translatesAutoresizingMaskIntoConstraints = NO; 
    UILayoutGuide * guide = self.view.safeAreaLayoutGuide; 
    [self.tableView.leadingAnchor constraintEqualToAnchor:guide.leadingAnchor].active = YES; 
    [self.tableView.trailingAnchor constraintEqualToAnchor:guide.trailingAnchor].active = YES; 
    [self.tableView.topAnchor constraintEqualToAnchor:guide.topAnchor].active = YES; 
    [self.tableView.bottomAnchor constraintEqualToAnchor:guide.bottomAnchor].active = YES; 

スイフト4

 tableView.translatesAutoresizingMaskIntoConstraints = false 
     if #available(iOS 11.0, *) { 
      let guide = self.view.safeAreaLayoutGuide 

      tableView.trailingAnchor.constraint(equalTo: guide.trailingAnchor).isActive = true 
      tableView.leadingAnchor.constraint(equalTo: guide.leadingAnchor).isActive = true 
      tableView.bottomAnchor.constraint(equalTo: guide.bottomAnchor).isActive = true 
      tableView.topAnchor.constraint(equalTo: guide.topAnchor).isActive = true 

     } else { 
      NSLayoutConstraint(item: tableView, attribute: .leading, relatedBy: .equal, toItem: view, attribute: .leading, multiplier: 1.0, constant: 0).isActive = true 
      NSLayoutConstraint(item: tableView, attribute: .trailing, relatedBy: .equal, toItem: view, attribute: .trailing, multiplier: 1.0, constant: 0).isActive = true 
      NSLayoutConstraint(item: tableView, attribute: .bottom, relatedBy: .equal, toItem: view, attribute: .bottom, multiplier: 1.0, constant: 0).isActive = true 
      NSLayoutConstraint(item: tableView, attribute: .top, relatedBy: .equal, toItem: view, attribute: .top, multiplier: 1.0, constant: 0).isActive = true 
     } 
1

コントローラーはUI のViewController(ないのUIViewController)から誘導された場合、c ellsは画面の下側によく見えません。

cells and home indicator look together

私はあなたが私の解決策があり、この場合には、navigationControllerを使用していると仮定:

//dummy view 
var bottomX: UIView? 


override func viewWillAppear(_ animated: Bool) { 
    super.viewWillAppear(animated) 
    if Device.isIPhoneX { 
     bottomX = UIView(frame: CGRect(x: 0, y: self.tableView.bounds.size.height - 34, width: self.tableView.bounds.size.width, height: 34)) 
     bottomX!.backgroundColor = self.tableView.backgroundColor 
     self.navigationController?.view.addSubview(bottomX!) 
    } 
} 

override func viewWillDisappear(_ animated: Bool) { 
    super.viewWillDisappear(animated) 
    bottomX?.removeFromSuperview() 
} 

ダミービューを削除し忘れ、結果はありません:

cells behind dummy view

このソリューションは非常に素晴らしいではありませんが、それは今

関連する問題