HL666
HL666

Reputation: 105

iPhone 16 safe area insets is too small

I need to add an admob banner to the bottom of my screen. I need to make sure to accommodate for safe area. This is what I did:

func addBanner(in vc: UIViewController) {
    ...
    bannerView = BannerView(adSize: AdHelper.adaptiveBannerSize(in: vc))
    guard let banner = bannerView else { return }
    
    banner.rootViewController = vc
    banner.load(Request())
    
    let x = (vc.view.frame.size.width - banner.adSize.size.width)/2
    let y = vc.view.frame.size.height - vc.view.safeAreaInsets.bottom - banner.adSize.size.height
    banner.frame = CGRect(x: x, y: y, width: banner.adSize.size.width, height: banner.adSize.size.height)
    vc.view.addSubview(banner)
}

enum AdHelper {
  static func adaptiveBannerSize(in vc: UIViewController) -> AdSize {
    let frame = vc.view.frame.inset(by: vc.view.safeAreaInsets)
    let viewWidth = frame.size.width
    return currentOrientationAnchoredAdaptiveBanner(width: viewWidth)
  }
}

Then I got the following result. Note that the left/right edges of the banner are "sliced-off" by the corner of iPhone 16.

Not sure if this violated admob policy. It would be great if i can avoid this.

You can download a sample project here (in the project I use constraints, but got the same result).

https://drive.google.com/file/d/1mw_uuW81hTyqjT1PotjAi-dwOJv6uyrk/view?usp=sharing

enter image description here

Upvotes: 0

Views: 64

Answers (0)

Related Questions