首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ADBannerView低于UITableViewController

ADBannerView低于UITableViewController
EN

Stack Overflow用户
提问于 2015-04-04 05:36:56
回答 1查看 330关注 0票数 1

我想将iAd横幅集成在tableView下面的UItableViewController中。目标是调整表视图的大小,并将其添加到UIViewController的底部,在本例中为UITableViewController。我开始考虑adBannerView是一个UIView,所以我在下面为一个UIView编写了代码,它成功了,但是当我试图用一个ADBannerView替换它时,它不会发生。ADBanner出现在正确的位置,但tableView大小丢失。

有人能试着理解原因并帮我找到更好的解决方案吗?不使用footerView是可行的吗?

这是密码。目前是Utils类中的静态方法。接下来,我将在另一个上下文中使用它,但是您应该能够轻松地自己测试它。

代码语言:javascript
复制
class ViewControllerUtils {
    class func showBanner<C:UIViewController where C:ADBannerViewDelegate> ( viewController:C)  {

        println("*** showBanner isLandscape:\(UIDevice.currentDevice().orientation.isLandscape)")

        // you don't care about it for the moment.
        var bannerHeight:CGFloat = 50.0
        if UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Pad{
            bannerHeight = 66.0
        } else if UIDevice.currentDevice().orientation.isLandscape {
            bannerHeight = 32.0
        }
        println("bannerHeight: \(bannerHeight)")

        // created a local variable in order to update the original frame
        var viewFrame  = viewController.view.frame

        UIView.animateWithDuration(1.0, animations: { () -> Void in
                        println("viewFrame \(viewFrame)")

            viewFrame.size.height -= bannerHeight
            viewController.view.frame = viewFrame
            println("viewFrame \(viewFrame)")

            }) { (ended:Bool) -> Void in

                var x = CGPoint(x: viewFrame.origin.x, y: viewFrame.origin.y + viewFrame.size.height)
                var bannerFrame = CGRect(origin:  x, size: CGSize(width: viewFrame.size.width, height: bannerHeight))

                var container = UIView(frame: bannerFrame)
                container.backgroundColor = UIColor.redColor()

                //without this line it works like expected.
                //with it tableview resizing is not applied anymore
                container.addSubview(ADBannerView(frame: CGRect(origin:  CGPointZero, size: CGSize(width: viewFrame.size.width, height: bannerHeight))))

                viewController.view.superview?.addSubview(container)
        }

    }

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-04 06:22:02

如果只需要TableViewController底部的横幅,就可以使用预构建的行为,将canDisplayBannerAds设置为true,如下所示:

代码语言:javascript
复制
import UIKit
import iAd

class MainViewController: UITableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        self.canDisplayBannerAds = true
    }

}
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29443149

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档