На некоторых контроллерах представления мой рекламный баннер будет отображаться над моей панелью задач (которую я хочу). Однако на других контроллерах представления это появляется под панелью инструментов; скрытый. Весь код одинаков для разных swift-файлов. Как мне go разместить рекламный баннер над панелью инструментов? Картинки включены:
Что я хочу: Что я не хочу:
---- Рабочее объявление код:
import UIKit
import GoogleMobileAds
class ViewController: UIViewController, GADBannerViewDelegate {
var bannerView: GADBannerView!
override func viewDidLoad(){
super.viewDidLoad()
//---------ADS----------------
// In this case, we instantiate the banner with desired ad size.
bannerView = GADBannerView(adSize: kGADAdSizeBanner)
addBannerViewToView(bannerView)
}
func addBannerViewToView(_ bannerView: GADBannerView) {
bannerView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(bannerView)
view.addConstraints(
[NSLayoutConstraint(item: bannerView,
attribute: .bottom,
relatedBy: .equal,
toItem: bottomLayoutGuide,
attribute: .top,
multiplier: 1,
constant: 1),
NSLayoutConstraint(item: bannerView,
attribute: .centerX,
relatedBy: .equal,
toItem: view,
attribute: .centerX,
multiplier: 1,
constant: 1)
])
bannerView.adUnitID = "ca-app-pub-9944401739416572/3708634126"
bannerView.rootViewController = self
bannerView.load(GADRequest())
}
// Forces Portrait
override var shouldAutorotate : Bool {
return false
}
override var supportedInterfaceOrientations : UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.portrait
}
//End of Forces Portrait */
не работает код:
import UIKit
import GoogleMobileAds
///You are using this class a UIViewCOntroller in storyBoard bbut hadnt provided **tablelist: UIViewController**
///This is Necessary in case when you are going to assign it to a UIVIewController
class toollist: UIViewController, UITableViewDataSource, UITableViewDelegate, GADBannerViewDelegate {
var bannerView: GADBannerView!
override func viewDidLoad(){
super.viewDidLoad()
self.navigationController?.navigationBar.barTintColor = UIColor.black
UINavigationBar.appearance().titleTextAttributes = \[NSAttributedString.Key.foregroundColor : UIColor.red\]
///You need to Sert datasource and Delegate as its not a TableViewController its just a Normal TableView
self.animalTableView.dataSource = self
self.animalTableView.delegate = self
self.view.backgroundColor = UIColor.black
//---------ADS-------------------------------------------
// In this case, we instantiate the banner with desired ad size.
bannerView = GADBannerView(adSize: kGADAdSizeBanner)
addBannerViewToView(bannerView)
}
func addBannerViewToView(_ bannerView: GADBannerView) {
bannerView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(bannerView)
view.addConstraints(
\[NSLayoutConstraint(item: bannerView,
attribute: .bottom,
relatedBy: .equal,
toItem: bottomLayoutGuide,
attribute: .top,
multiplier: 1,
constant: 1),
NSLayoutConstraint(item: bannerView,
attribute: .centerX,
relatedBy: .equal,
toItem: view,
attribute: .centerX,
multiplier: 1,
constant: 1)
\])
bannerView.adUnitID = "ca-app-pub-9944401739416572/3708634126"
bannerView.rootViewController = self
bannerView.load(GADRequest())
}
//--------------------------LIST Specs-------------------------------------------------------//
let tool = \["APGAR Calculator","Dopamine Calculator","GCS Calculator","Parkland Burn Formula","Rule of Nines (Adult)","Epocrates","Event Logger","Rate Calculator","Medical Sign Language"/*"EKG Examples"*/\]
///You did not connected a outlet of tableView
///as its not a tableViewController just a TableView so it should be Connected
@IBOutlet weak var animalTableView: UITableView!
///Set elements in cell
func tableView( _ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCell(withIdentifier: "listoftools"/*Identifier*/, for: indexPath)
cell.textLabel?.text = tool\[indexPath.row\]
// FONT STYLE
cell.textLabel?.textColor = UIColor.white
cell.detailTextLabel?.font = UIFont.boldSystemFont(ofSize: 30.0)
cell.textLabel?.textAlignment = .center
self.animalTableView.backgroundColor = UIColor.clear
cell.textLabel?.backgroundColor = UIColor.black
return cell
}
// var AMPT : \[UIImage\] = \[
// UIImage(named: "AMPT")! \]
var sign : \[UIImage\] = \[
UIImage(named: "signlang1")!,
UIImage(named: "signlang2")!,
UIImage(named: "signlang3")!,
UIImage(named: "signlang4")!,
UIImage(named: "signlang5")!,
UIImage(named: "signlang6")!,
UIImage(named: "signlang7")!,
UIImage(named: "signlang8")!,
\]
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return tool.count
}
//--------------------------Respiratory List--------------------
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
let Tools = UIStoryboard(name: "Tools", bundle: nil)
let Vc = self.storyboard?.instantiateViewController(withIdentifier: "imageViewController") as! imageViewController
let apgarcalc = Tools.instantiateViewController(withIdentifier: "apgarcalculator") as! DopamineCalculator
let dopecalc = Tools.instantiateViewController(withIdentifier: "dopaminecalculator") as! DopamineCalculator
let gcscalc = Tools.instantiateViewController(withIdentifier: "gcscalculator") as! DopamineCalculator
let ruleofninecalc = Tools.instantiateViewController(withIdentifier: "adultruleofnines") as! DopamineCalculator
let burncalc = Tools.instantiateViewController(withIdentifier: "burnpercentcalculator") as! DopamineCalculator
let evenlog = Tools.instantiateViewController(withIdentifier: "OPENTIME") as! eventLogger
let tempo = Tools.instantiateViewController(withIdentifier: "taptempo") as! taptempo
// let ekg = Tools.instantiateViewController(withIdentifier: "ekglist") as! ekglist
// let Vc = self.storyboard?.instantiateViewController(withIdentifier: "imageViewController") as! imageViewController
switch indexPath.row
{
case 0:
self.navigationController?.pushViewController(apgarcalc, animated: true)
break;
case 1:
self.navigationController?.pushViewController(dopecalc, animated: true)
break;
case 2:
self.navigationController?.pushViewController(gcscalc, animated: true)
break;
case 3:
self.navigationController?.pushViewController(burncalc, animated: true)
break;
case 4:
self.navigationController?.pushViewController(ruleofninecalc, animated: true)
break;
case 5:
//epocrates
if let url = URL(string: "http://www.epocrates.com") { UIApplication.shared.openURL(url)}
break;
case 6:
self.navigationController?.pushViewController(evenlog, animated: true)
break;
case 7:
self.navigationController?.pushViewController(tempo, animated: true)
break;
case 8:
Vc.passedArray = sign
self.navigationController?.pushViewController(Vc, animated: true)
break;
default:
self.navigationController?.pushViewController(evenlog, animated: true)
}
}