【问题标题】:Monotouch.Dialog and iAdsMonotouch.Dialog 和 iAds
【发布时间】:2013-11-17 21:59:07
【问题描述】:

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

添加 UIViewController,然后添加 ADBannerViewMonotouch.Dialog 是最佳做法,还是应该添加iAds 视图到 Monotouch.Dialog 视图控制器?

【问题讨论】:

    标签: ios xamarin xamarin.ios iad monotouch.dialog


    【解决方案1】:

    我创建了一个运行良好的包装 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 ();
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-07
      • 1970-01-01
      • 2012-03-04
      • 1970-01-01
      相关资源
      最近更新 更多