所以在iAd出现后调整视图大小时遇到问题,它阻塞了视图的底部部分。我可以从已经为横幅腾出空间开始,但这看起来不是很好,看起来像一个空的白色空间。我希望在显示时基于iAd更新视图,当它消失时,两个视图都以编程方式添加。这是一些代码
func bannerViewDidLoadAd(banner: ADBannerView!) {
self.bannerView1.hidden = false
print("BANNERVIEWSHOWN")
}
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
self.bannerView1.hidden = true
print("BANNERVIEWHIDDEN")
}
在viewdidload()
中 bannerView1.translatesAutoresizingMaskIntoConstraints = false
bannerView1.delegate = self
bannerView1.hidden = true
self.pageMenu = CAPSPageMenu(viewControllers: controllerArray, frame: CGRectMake(0.0, 0.0, self.view.frame.width, self.view.frame.height), pageMenuOptions: parameters)
pageMenu!.delegate = self
self.view.addSubview(self.pageMenu!.view)
self.view.addSubview(bannerView1)
let viewsDictionary = ["bannerView": bannerView1]
view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[bannerView]|", options: [], metrics: nil, views: viewsDictionary))
view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:[bannerView]|", options: [], metrics: nil, views: viewsDictionary))
我将如何制作它,以便它根据iAd增长和缩小? 我知道如果是使用界面构建器制作高度约束我可以玩,但不是......
答案 0 :(得分:0)
使用约束调整大小的最简单方法:
// Setup our BannerView
bannerView = ADBannerView(adType: .Banner)
bannerView.frame = CGRectMake(0,0,bannerView.frame.width,bannerView.frame.height)
bannerView.translatesAutoresizingMaskIntoConstraints = false
bannerView.delegate = self
bannerView.hidden = true
view.addSubview(bannerView)
let viewsDictionary = ["bannerView": bannerView]
view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[bannerView]|", options: [], metrics: nil, views: viewsDictionary))
view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[bannerView]", options: [], metrics: nil, views: viewsDictionary))