gpt4 book ai didi

ios - Monotouch.Dialog 和 iAds

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:17:18 25 4
gpt4 key购买 nike

我正在玩 iAds。我想将它添加到基本上是一堆 Monotouch.Dialog View 的应用程序。

最好的做法是添加一个UIViewController,然后添加一个ADBannerView 和一个Monotouch.Dialog,或者我应该添加iAds View 到 Monotouch.Dialog ViewController?

最佳答案

我创建了一个很好用的包装器 ViewController,只需传入主应用程序的 View ,如 TabBar 或 SplitView 等,并使用 IADViewController 作为 RootViewCONtroller:

     public partial class IADViewController : UIViewController
{
private UIViewController _anyVC;
private MonoTouch.iAd.ADBannerView _ad;

public IADViewController (UIViewController anyVC)
{
_anyVC = anyVC;
}

public override void ViewDidLoad ()
{
base.ViewDidLoad ();

View.AddSubview (_anyVC.View);


if (Common.Device.Is6AtLeast && Social.IsiAdCountry) {

try {
_ad = new MonoTouch.iAd.ADBannerView (MonoTouch.iAd.ADAdType.Banner);
_ad.Hidden = true;
_ad.FailedToReceiveAd += HandleFailedToReceiveAd;
_ad.AdLoaded += HandleAdLoaded;
View.BackgroundColor = UIColor.Clear;
_anyVC.View.Frame = View.Bounds;
View.AddSubview (_ad);
} catch {
}
} else {
Resize ();
}
}

public override void DidRotate (UIInterfaceOrientation fromInterfaceOrientation)
{
base.DidRotate (fromInterfaceOrientation);
Resize ();
}

public override void ViewDidAppear (bool animated)
{
base.ViewDidAppear (animated);
Resize ();
}

void Resize ()
{

UIView.Animate (.25,
() => {
if (_ad !=null && _ad.Hidden == false) {
_anyVC.View.Frame = new RectangleF (0, 0, this.View.Bounds.Width, this.View.Bounds.Height - _ad.Frame.Height);
} else {
_anyVC.View.Frame = View.Bounds;
}
});
if(_ad!=null)
_ad.Frame = new RectangleF (0, _anyVC.View.Bounds.Height, this.View.Bounds.Width, _ad.Frame.Height);
}

void HandleAdLoaded (object sender, EventArgs e)
{
if (_ad == null)
return;
_ad.Hidden = false;
Resize ();
}

void HandleFailedToReceiveAd (object sender, AdErrorEventArgs e)
{
if (_ad == null)
return;
_ad.Hidden = true;
Resize ();
}
}

关于ios - Monotouch.Dialog 和 iAds,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20036725/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com