iAd interaction on iPad screws up interface
Hej guys,
I implemented iAd via AdWhirl in my recent iPad Application in which I need to manually adjust the interface on rotation events. When my app is in landscape and the user taps the ad the interface is forced to rotate to portrait mode. This is fine as long as the app is dismissed because the status bar seems to be rotatet but the interface strangely didn't got any notifications to rotate so everything (which means really everything!) is kinda screwed up. Any suggestions what is ca开发者_JAVA技巧using this odd behavior? Many thanks, Tim
I am getting exactly the same problem, had thought maybe it is a MonoTouch issue. Will be good to see if anyone knows why this is. I have tried to force it to rotate back but have had no luck.
In the mean time I am just going to release my app, call it a known bug.
EDIT: Here is a test ViewController I was using in MonoTouch.
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;
}
}
}
One funky thing I did come across is that on the iPad (3rd Gen) the ShouldAutorotateToInterfaceOrientation gets called 3 times, then ViewDidLayoutSubviews, then ActionFinished but on the iPhone (3GS) ShouldAutorotateToInterfaceOrientation gets called once, and then ActionFinished gets called once.
Also with the iPad if I lock the view rotation in landscape then bring up the ad then dismiss it, it changes it to portrait for me.
精彩评论