BannerView doesn't adjust after orientation from landscape to portrait in iOS

40 views
Skip to first unread message

User345738945

unread,
Aug 6, 2025, 5:21:49 AM Aug 6
to Google Mobile Ads SDK Developers
Hi,
I am using the SwiftUI example  SwiftUI Demo BannerView  and rather than giving a fixed width, I read the width from GeometryReader. After orienting to landscape the banner view redraws nicely with the updated AdSize width, however the redrawing back to portrait from landscape causes the banner view to pour out of the screen boundaries. The orientation change from portrait(the start) to landscape works, but the orientation change from landscape to portrait doesn't work (the banner view pours out of screen). 
The updated BannerContentView is given below.


struct BannerContentView : View {

let navigationTitle : String


// [START add_banner_to_view]

var body : some View {

GeometryReader { geometry in

VStack {

Spacer ()

HStack {

Spacer ()

var adSize = currentOrientationAnchoredAdaptiveBanner(width: geometry. size . width * 0.90 )

BannerViewContainer (adSize)

                        . frame ( width : adSize. size . width , height : adSize. size . height )

Spacer ()

                }

            }

            . navigationTitle ( navigationTitle )

        }

    }

}


When I debug the adSize, the width values seem to be consistent between orientation changes (between orientations, width values are consistent). Somehow, the portrait drawing of the BannerView after landscape is problematic.

Is there a fixed for this error? What would you suggest? Thank you.

User345738945

unread,
Aug 6, 2025, 7:39:33 AM Aug 6
to Google Mobile Ads SDK Developers
The screenshot of the erroneous banner placement after orientation from landscape to portrait:
Simulator Screenshot - iPhone 16 Pro Max - 2025-08-06 at 14.31.52.png

Mobile Ads SDK Forum Advisor

unread,
Aug 6, 2025, 11:12:27 AM Aug 6
to gork...@gmail.com, google-adm...@googlegroups.com

Hi,

I've raised this concern to the wider team and will get back to you once I receive any updates on it. Meanwhile, your patience is highly appreciated.


Thanks,
Google Logo
Mobile Ads SDK Team

Feedback
How was our support today?

rating1 rating2 rating3 rating4 rating5
[2025-08-06 15:11:26Z GMT] This message is in relation to case "ref:!00D1U01174p.!500Ht01syF2I:ref" (ADR-00328870)



Mobile Ads SDK Forum Advisor

unread,
Sep 3, 2025, 3:00:44 PM (4 days ago)  Sep 3
to gork...@gmail.com, google-adm...@googlegroups.com

Hi,

We received an update from the wider team that GeometryReader is not the most reliable API for handling orientation changes in SwiftUI. Instead, it's recommended to use UIKit notifications or the sizeClass environment variable (e.g., @Environment(\.horizontalSizeClass) var horizontalSizeClass ) to respond to size change events.

I hope this helps! Let me know if you have any other questions.

Thanks,
Google Logo
Mobile Ads SDK Team

Feedback
How was our support today?

rating1 rating2 rating3 rating4 rating5

[2025-09-03 18:59:46Z GMT] This message is in relation to case "ref:!00D1U01174p.!500Ht01syF2I:ref" (ADR-00328870)



Reply all
Reply to author
Forward
0 new messages