在Swift中,我尝试在视图顶部使用NSLayoutConstraints添加Google智能广告横幅,但在状态栏下方增加14点。我现在已经尝试了各种不同的属性和top或topLayoutGuide。
let xConstraint = NSLayoutConstraint(item: bannerView, attribute: .centerX,
relatedBy: .equal, toItem: self.view, attribute: .centerX, multiplier: 1, constant: 0)
let pinTop = NSLayoutConstraint(item: bannerView, attribute: .top,
relatedBy: .equal, toItem: self.topLayoutGuide, attribute: .top, multiplier: 1, constant: 14)
self.view.addSubview(bannerView)
self.view.addConstraint(xConstraint)
self.view.addConstraint(pinTop)
答案 0 :(得分:0)
您将横幅固定在topLayoutGuide
的顶部,但您真正想要的是topLayoutGuide
的底部,以便它会从状态栏:
let pinTop = NSLayoutConstraint(item: bannerView,
attribute: .top,
relatedBy: .equal,
toItem: self.topLayoutGuide,
attribute: .bottom,
multiplier: 1,
constant: 14)