嘿所以我一直在尝试在我的应用程序的拆分视图控制器下面实现广告横幅视图。我设法通过创建一个BannerViewController
来实现它,它调整了splitViewController的大小并将横幅放在底部,这是有效的。但是,现在我注意到在TableViewController中点击列表中的项目在iPhone上不起作用。它在iPad上保持选择状态,所以它必须认为它在iPad上,并且必须在主机旁边显示细节。 segue在Interface Builder中从UITableViewCell连接到详细视图的导航控制器。在实施横幅控制器之后,它一切正常,但是今天早上就停止了。
我尝试在didSelectRowAtIndexPath中调用performSegue,每次调用prepareForSegue
但通常在iPhone上没有显示任何内容。
这是BannerViewController
:
class BannerViewController: UIViewController, GADBannerViewDelegate {
var bannerView = GADBannerView()
var showingBanner = false
var contentView, bannVC: UIView!
var originalFrame: CGRect!
init(contentVC: UIViewController) {
contentView = contentVC.view
originalFrame = contentView.frame // Store the original frame of the content view for later use
super.init(nibName: nil, bundle: nil)
// If banner is hidden, position off screen (x > window.height) and make contentView size of window
view.addSubview(contentView)
// Create banner view
setupAds()
}
// Required init, just call super
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
// Update the position of the banner on the screen
override func viewDidLayoutSubviews() {
bannerView.frame = CGRect(x: 0, y: contentView.frame.size.height, width: contentView.frame.size.width, height: 50)
}
// MARK: - Adverts
// Checks if ads have been disabled by buying the in app purchase
func checkAdsDisabled() -> Bool {
return Product.findBy(identifier: ProductRepo.DisableAds)?.purchased ?? false
}
func setupAds() {
if (!checkAdsDisabled()) {
// Ads have not been disabled, set them up
bannerView.adUnitID = "ca-app-pub-123456/xyz"
bannerView.translatesAutoresizingMaskIntoConstraints = false
bannerView.adSize = kGADAdSizeSmartBannerPortrait
bannerView.delegate = self
bannerView.rootViewController = self
let request: GADRequest = GADRequest()
request.testDevices = ["xyz"] // My iPhone
bannerView.load(request)
// Initially position off screen
view.addSubview(bannerView)
hideBanner()
}
}
// Hide banner and update view positions
func hideBanner() {
contentView.frame.size.height = originalFrame.size.height
view.layoutSubviews()
showingBanner = false
}
// Show banner and update view positions
// Called by adViewDidReceiveAd
func showBanner() {
contentView.frame.size.height = contentView.superview!.frame.size.height - bannerView.frame.size.height
view.layoutSubviews()
showingBanner = true
}
// MARK: - GADBannerViewDelegate
/// Tells the delegate an ad request loaded an ad.
func adViewDidReceiveAd(_ bannerView: GADBannerView!) {
print("adViewDidReceiveAd: Banner loaded")
if !showingBanner{
showBanner()
}
}
}
如果有帮助,我也在主视图中使用SearchController。当点击搜索栏时,我收到警告Presenting view controllers on detached view controllers is discouraged
,这可能是相关的,但我无法获得任何信息。