When playing iAd ads at the bottom, what's the Y value?

I saw an article saying if I want to show iAd at the bottom of the screen, I should do something like this:

local adY = display.contentHeight - 66 if not device.is\_iPad then if display.contentHeight \> than display.contentWidth then -- portrait adY = display.contentHeight - 50 else adY = display.contentHeight - 32 end end ads.show( "banner", { x=0, y=adY } ) 

I can totally understand and I use similar code in my app, however the result is quite weird:

(1) For iPhone 4S, the Ad is not at the exact bottom. It’s a little bit above bottom.

(2) I tried to change y value: y=display.contentHeight (without any offset), then the ad shows at the exact bottom

(3) I tried similar steps on iPhone 5, the ad always appear above bottom.

How to make iAd ad shows at the exact bottom after all? Is there anything changed?

Hi Joe,

I agree, the placement is weird.  In a portrait app using a config.lua similar to this one (http://www.coronalabs.com/blog/2013/09/10/modernizing-the-config-lua/), I’ve been using display.contentHeight as the y-value for ads.show(), and it has in fact been placing it right along the bottom edge on all the devices I’ve tested on (iPhone 4, iPhone 5, and iPad 3).

  • Andrew

My config.lua is 320x480 with letterbox.

I can’t figure out a way to put the ad right along the bottom edge… :frowning:

What you list as option (2) is what’s working for me.  (Counterintuitive, since one would think an offset would be required for the height of the ad, but apparently not when placing on the bottom.)  What exactly happens when you do (2)?

  • Andrew

When I do option (2), iPhone 4S works, the ad is placed along the bottom edge of the screen.

However, iPhone 5 does not work for option (2)

iAd plugin is from Corona, right? Maybe I should submit a bug to Corona?

If your config.lua is setting the width and height to exactly 320 by 480, then option (2) won’t work.  Instead, try setting your config.lua to what is shown in the blog post I linked.

Alternatively, if you want to keep your config.lua as it is, try option (2), but set y = display.contentHeight - display.screenOriginY.

  • Andrew

My app is already in public, I can’t make such a scaling change, that will require a lot of things to be remade.

I already tried “display.contentHeight - display.screenOriginY” before I posted this question actually. And for iPhone 5, it’s not working. Both 

y=display.contentHeight

or 

y=display.contentHeight - display.screenOriginY

leaves a space under the ad.

Was working on this last night. This is the only way I got it to work. I only figured it out through trial and error, the math makes no sense to me.

[lua]

if(display.screenOriginY < -80) then

    adX, adY = display.screenOriginX, display.contentHeight - display.screenOriginY*2 - 90

    ads.show(adType, {x=adX, y=adY, interval=30})

else

    adX, adY = display.screenOriginX, display.contentHeight

    ads.show(adType, {x=adX, y=adY, interval=30})

end

[/lua]

For the seemingly random numbers:

display.screenOriginY on an iPhone 5 registers as -88. -80 is kind of arbitrary, I just wanted to make sure it would get checked.

90 is the banner height for iPhone devices. For iPad devices it’s a little shorter, about 66 pixels.

Edit: My config file defines the project as 640 width by 960 height, if that makes a difference.

@sirnemo

wow, that’s great! I can’t believe you did this! I will try it out later.

but it’s really weird… is this something controlled by Corona SDK and can be fixed by them?

Hi Joe,

I agree, the placement is weird.  In a portrait app using a config.lua similar to this one (http://www.coronalabs.com/blog/2013/09/10/modernizing-the-config-lua/), I’ve been using display.contentHeight as the y-value for ads.show(), and it has in fact been placing it right along the bottom edge on all the devices I’ve tested on (iPhone 4, iPhone 5, and iPad 3).

  • Andrew

My config.lua is 320x480 with letterbox.

I can’t figure out a way to put the ad right along the bottom edge… :frowning:

What you list as option (2) is what’s working for me.  (Counterintuitive, since one would think an offset would be required for the height of the ad, but apparently not when placing on the bottom.)  What exactly happens when you do (2)?

  • Andrew

When I do option (2), iPhone 4S works, the ad is placed along the bottom edge of the screen.

However, iPhone 5 does not work for option (2)

iAd plugin is from Corona, right? Maybe I should submit a bug to Corona?

If your config.lua is setting the width and height to exactly 320 by 480, then option (2) won’t work.  Instead, try setting your config.lua to what is shown in the blog post I linked.

Alternatively, if you want to keep your config.lua as it is, try option (2), but set y = display.contentHeight - display.screenOriginY.

  • Andrew

My app is already in public, I can’t make such a scaling change, that will require a lot of things to be remade.

I already tried “display.contentHeight - display.screenOriginY” before I posted this question actually. And for iPhone 5, it’s not working. Both 

y=display.contentHeight

or 

y=display.contentHeight - display.screenOriginY

leaves a space under the ad.

Was working on this last night. This is the only way I got it to work. I only figured it out through trial and error, the math makes no sense to me.

[lua]

if(display.screenOriginY < -80) then

    adX, adY = display.screenOriginX, display.contentHeight - display.screenOriginY*2 - 90

    ads.show(adType, {x=adX, y=adY, interval=30})

else

    adX, adY = display.screenOriginX, display.contentHeight

    ads.show(adType, {x=adX, y=adY, interval=30})

end

[/lua]

For the seemingly random numbers:

display.screenOriginY on an iPhone 5 registers as -88. -80 is kind of arbitrary, I just wanted to make sure it would get checked.

90 is the banner height for iPhone devices. For iPad devices it’s a little shorter, about 66 pixels.

Edit: My config file defines the project as 640 width by 960 height, if that makes a difference.

@sirnemo

wow, that’s great! I can’t believe you did this! I will try it out later.

but it’s really weird… is this something controlled by Corona SDK and can be fixed by them?

Here is my update:

I saw similar question in this thread: 

http://forums.coronalabs.com/topic/28563-iads/page-3

It is raised by “deleurapps”, but no one really answered his question why the following formula works to place the ad at the bottom of the screen. He posted code like this to show ads in the bottom

local adY = display.contentHeight - display.screenOriginY ads.show( "banner", { x=originx, y=adY } )

I have tested this code, and it does work. (@sirnemo, your code is actually the same, “display.contentHeight - display.screenOriginY*2 - 90” is 2 pixels difference than “display.contentHeight - display.screenOriginY”)

Anyway, I too have the same question as “deleurapps” has:

Why does this code work to place iads (including admob) at the bottom of the screen??  :o 

Can anyone in Corona explain this?

It’s really weird. For example, 

display.contentHeight - display.screenOriginY = 524 - (-44) = 568  for iPhone 5

Why would this work? 

Does Corona ad plugin make the ad become “bottom-aligned” automatically when the Y is over certain value??

Hi Joe,

You may be interested in this thread, specifically the last few posts: http://forums.coronalabs.com/topic/41760-iads-not-clickable-anyone-else-having-this-issue/page-2.

Previously it seems that the y value was bottom-aligning iAd banners, but now it’s top-aligning it, consistent with the API documentation.

  • Andrew

@aukStudios Thanks for letting me know about the thread. Are you sure it’s now top-aligning? From the y value calculation, it still looks like bottom-aligning. Following is my experiments, replied to that thread too.

It’s now very confusing about placing the ad at the bottom of the screen.

 

From dchan’s earlier post,

You’re correct they should align with the top of the ad and this has been changed.

 

Does it mean the ads should all align with the top now?

 

However, from my testing, it’s still not consistent, please see the following results for the inconsistency: (I am using the latest daily build - CoronaSDK 2013.2100 and my config.lua is 320x480, letterbox)

 

(1) If y = display.contentHeight, iAd shows at the bottom for iPad (because iPad’s display.screenOriginalY = 0), but for iPhone 5S, iAd shows above the bottom. For admob, it behaves the same as iAd.

 

(2) If y = display.contentHeight - display.screenOriginalY, iPad is fine for both iAd & admob (again, I think it’s because display.screenOriginal is 0 for iPad). For iPhone 5S, iAd shows at the exact bottom, which is good. But for admob, the ad shows above the bottom for iPhone 5S. 

 

Besides, admob shows below the bottom for Galaxy Tab 3. (part of the top area of admob ad shows up)

 

(3) If y = display.contentHeight - display.screenOriginalY  * 2 , admob shows correctly at the bottom for iPhone 5S, but below the bottom for Galaxy Tab 3. For Galaxy Tab 3, in order to show at the exact bottom, I found y = display.contentHeight - display.screenOriginalY  * 2 - 63  would do. (I don’t know how to get this number, 63. I started with 50 & 66, and adjusted one pixel at at a time to get 63.) BTW, display.screenOriginalY for Galaxy Tab 3 is -16.

 

The conclusions:

 

(1) For iAd, it still looks like it’s “bottom-aligning”, is this final?

 

(2) For admob, the y value behaves differently than iAd, why is that? is this intended behavior? What’s the rule?

 

(3) For admob, iOS device & Android device seem to behave differently? How to correctly calculate the y value to place admob at the exact bottom for both iOS & Android devices?

 

Please someone shed some light on this. I am about to release a new version with iAd & admob before iTunes closes for the holidays. It’s a total mess right now.   :unsure:  Thanks.