iPad上的iAd交互搞砸了界面

时间:2011-08-05 09:45:59

标签: iphone ipad interface orientation iad

Hej家伙,

我在最近的iPad应用程序中通过AdWhirl实现了iAd,我需要手动调整旋转事件的界面。当我的应用处于横向状态且用户点按广告时,界面将被强制旋转为纵向模式。只要应用程序被解除,这是很好的,因为状态栏似乎是rotatet但是接口奇怪地没有任何通知旋转所以一切(这意味着真的一切!)有点搞砸了。是什么原因造成这种奇怪的行为? 非常感谢, 添

1 个答案:

答案 0 :(得分:0)

我遇到了完全相同的问题,原本认为这可能是MonoTouch问题。 很高兴看到是否有人知道这是为什么。我曾试图强迫它旋转但没有运气。

与此同时,我将发布我的应用程序,将其称为已知错误。

编辑: 这是我在MonoTouch中使用的测试ViewController。

using System;
using MonoTouch.iAd;
using MonoTouch.UIKit;
using MonoTouch.Foundation;


namespace ADBannerRotate
{
    public class ViewController : UIViewController
    {

        private ADBannerView adBannerView = null;

        public ViewController()
        {
        }

        public override void ViewDidLayoutSubviews()
        {
            base.ViewDidLayoutSubviews();
            Console.WriteLine("ViewDidLayoutSubviews");


            Console.WriteLine("ViewDidLayoutSubviews StatusBarOrientation: " + UIApplication.SharedApplication.StatusBarOrientation);
            Console.WriteLine("ViewDidLayoutSubviews Orientation: " + UIDevice.CurrentDevice.Orientation);

        }

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            Console.WriteLine("ViewDidLoad");


            adBannerView = new ADBannerView();
            adBannerView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;


            NSMutableSet requiredContentSizeIdentifiers = new NSMutableSet(); 
            requiredContentSizeIdentifiers.Add(ADBannerView.SizeIdentifierPortrait);
            requiredContentSizeIdentifiers.Add(ADBannerView.SizeIdentifierLandscape); 
            adBannerView.RequiredContentSizeIdentifiers = requiredContentSizeIdentifiers;

            if (UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.LandscapeLeft || UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.LandscapeRight)
            {
                adBannerView.CurrentContentSizeIdentifier = ADBannerView.SizeIdentifierLandscape;
            }
            else 
            {
                adBannerView.CurrentContentSizeIdentifier = ADBannerView.SizeIdentifierPortrait;
            }

            adBannerView.ActionFinished += delegate(object sender, EventArgs e) {
                Console.WriteLine("ActionFinished");

                Console.WriteLine("ActionFinished StatusBarOrientation: " + UIApplication.SharedApplication.StatusBarOrientation);
                Console.WriteLine("ActionFinished Orientation: " + UIDevice.CurrentDevice.Orientation);

            };
            adBannerView.AdLoaded += delegate(object sender, EventArgs e) {
                Console.WriteLine("AdLoaded - " + adBannerView.CurrentContentSizeIdentifier);
            };
            adBannerView.FailedToReceiveAd += delegate(object sender, AdErrorEventArgs e) {
                Console.WriteLine("FailedToReceiveAd");
            };
            adBannerView.WillLoad += delegate(object sender, EventArgs e) {
                Console.WriteLine("WillLoad");
            };

            View.AddSubview(adBannerView);
        }

        public override bool ShouldAutorotateToInterfaceOrientation(UIInterfaceOrientation toInterfaceOrientation)
        {
            Console.WriteLine("ShouldAutorotateToInterfaceOrientation - " + toInterfaceOrientation);
            Console.WriteLine("ShouldAutorotateToInterfaceOrientation StatusBarOrientation: " + UIApplication.SharedApplication.StatusBarOrientation);
            Console.WriteLine("ShouldAutorotateToInterfaceOrientation Orientation: " + UIDevice.CurrentDevice.Orientation);


            if (adBannerView != null)
            {
                if (toInterfaceOrientation == UIInterfaceOrientation.LandscapeLeft || toInterfaceOrientation == UIInterfaceOrientation.LandscapeRight)
                {
                    adBannerView.CurrentContentSizeIdentifier = ADBannerView.SizeIdentifierLandscape;
                }
                else
                {
                    adBannerView.CurrentContentSizeIdentifier = ADBannerView.SizeIdentifierPortrait;
                }
            }
            return true;
        }
    }
}

我遇到的一个时髦的事情是,在iPad(第三代)上,ShouldAutorotateToInterfaceOrientation被调用3次,然后是ViewDidLayoutSubviews,然后是ActionFinished,但在iPhone(3GS)上,ShouldAutorotateToInterfaceOrientation被调用一次,然后ActionFinished被调用一次。

如果我在横向上锁定视图旋转,然后调出广告,然后将其关闭,它会将其更改为肖像。