来自TabView栏的NSLayoutConstraint o导航栏

时间:2015-07-14 20:20:31

标签: ios swift uitableview nslayoutconstraint

我正在搞乱Swift中的约束,并且我有一个真正的唠叨问题是在导航栏和标签栏上设置距离。有没有办法设置约束使自己与顶部保持一定距离,包括导航标题(或包括标签栏的底部)而不是屏幕最左上角的真实(0,0)?下面的示例代码只是为了向您展示我正在处理的内容。

让viewsDictionary = [" tableView&#34 ;: tableView," changeDirectionButton":changeDirectionButton," adBanner&#34 ;: appleAd]

self.view.addSubview(tableView)
self.view.addSubview(changeDirectionButton)
self.view.addSubview(appleAd)

let view_constraint_H = NSLayoutConstraint.constraintsWithVisualFormat(
    "H:|-[changeDirectionButton(60)]",
        options: NSLayoutFormatOptions(0), metrics: nil, views: viewsDictionary)
let view_constaint_H2 = NSLayoutConstraint.constraintsWithVisualFormat(
    "H:|[tableView]|",
        options: NSLayoutFormatOptions(0), metrics: nil, views: viewsDictionary)
let view_constraint_V = NSLayoutConstraint.constraintsWithVisualFormat(
    "V:|-70-[changeDirectionButton(60)]-[tableView][adBanner]-60-|", 
        options: NSLayoutFormatOptions(0), metrics: nil, views: viewsDictionary)

self.view.addConstraints(view_constraint_V)
self.view.addConstraints(view_constraint_H)
self.view.addConstraints(view_constaint_H2)

1 个答案:

答案 0 :(得分:0)

对于底部和顶部,我添加了:

super.edgesForExtendedLayout = UIRectEdge.Top & UIRectEdge.Bottom

哪个有效