簡體   English   中英

Monotouch.Dialog和iAds

[英]Monotouch.Dialog and iAds

我正在使用iAds。 我想將其添加到基本上是一堆Monotouch.Dialog視圖的應用程序中。

是添加一個UIViewController,然后添加一個ADBannerViewMonotouch.Dialog它的最佳實踐,或者我應該添加的iAds着眼於Monotouch.Dialog的ViewController?

我創建了一個效果很好的包裝器ViewController,只需將主應用程序的視圖(如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 ();
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM