How to position banner ads over UITabbar?

2020-06-06 07:01发布

问题:

I want to use ads in my application. I added a tab bar as shown below. I would like the advertisement to appear right above the tab bar.

To do this I added the bannerView as a subview on the view that I created. However, it did not show the banner.

How would you create the structure show below?

googleBannerView = GADBannerView(adSize: kGADAdSizeSmartBannerPortrait)
        googleBannerView.adUnitID = "ca-app-pub-5378899862041789/8532100959"
        googleBannerView.rootViewController = self
        let request: GADRequest = GADRequest()
        googleBannerView.loadRequest(request)
        googleBannerView.frame = CGRectMake(0, adBannerView.layer.frame.minY, googleBannerView.frame.size.width, googleBannerView.frame.size.height)
        //googleBannerView.frame = adBannerView.frame
        adBannerView.addSubview(googleBannerView!)

回答1:

I solved the problem by positioning the ad with CGRectMake().

googleBannerView.frame = CGRectMake(0, (view.bounds.height - googleBannerView.frame.size.height) - 49, self.view.bounds.size.width, 49)

49 is the height of UITabBar.



标签: swift ads