- Home /
iAds from ADBannerView offset on orientation change
I've integrated iAds into my iOS game using ADBannerView from UnityEngine.iOS.ADBannerView. Everything works as expected, except for one problem. When an ad is generated in any screen orientation, removed while in landscape, and then the device is changed back into portrait, the banner moves toward the middle of the screen as can be seen in the attached screenshot. I have no idea how it manages to get in the middle of the screen, as I specifically set its layout to TopCenter. Does anyone know what could be going on here?
Here is the code I'm using to manage iAds:
using UnityEngine;
using System.Collections;
using ADBannerView = UnityEngine.iOS.ADBannerView;
public class AdControl : MonoBehaviour {
private ADBannerView banner = null;
void OnBannerLoaded(){
banner.visible = true;
Debug.Log ("Banner loaded");
}
void OnBannerClicked(){
Debug.Log ("Banner clicked");
}
public void hideAd(){
if (banner == null)
return;
Debug.Log ("Hide " + Time.unscaledTime);
banner.visible = false;
banner = null;
ADBannerView.onBannerWasLoaded -= OnBannerLoaded;
ADBannerView.onBannerWasClicked -= OnBannerClicked;
}
public void showAd(){
if (banner != null)
return;
Debug.Log ("Show " + Time.unscaledTime);
banner = new ADBannerView(ADBannerView.Type.Banner, ADBannerView.Layout.TopCenter);
ADBannerView.onBannerWasClicked += OnBannerClicked;
ADBannerView.onBannerWasLoaded += OnBannerLoaded;
}
}
iad.jpg
(122.5 kB)
Comment
Answer by Mintah · Nov 15, 2015 at 08:13 AM
This may not be the best solution however, you may place this inside an update function:
if(banner.visible==true){
if(banner.position.y!= Screen.height-banner.size.y){
banner.position = new Vector2(Screen.width/2,Screen.height-banner.size.y);
}
}