How do I position smart banner at top of the Safe area (phoneX)?

145 views
Skip to first unread message

Ismael Machado

unread,
Dec 12, 2018, 7:23:32 PM12/12/18
to google-adm...@googlegroups.com
currently the docs only state how to position on botttom of safe area for a smart banner , im unsure of what values exactly to change and the value I change them to ? 

#pragma mark - view positioning

- (void)positionBannerViewFullWidthAtBottomOfSafeArea:(UIView *_Nonnull)bannerView NS_AVAILABLE_IOS(11.0) {
 
// Position the banner. Stick it to the bottom of the Safe Area.
 
// Make it constrained to the edges of the safe area.
 
UILayoutGuide *guide = self.view.safeAreaLayoutGuide;

 
[NSLayoutConstraint activateConstraints:@[
   
[guide.leftAnchor constraintEqualToAnchor:bannerView.leftAnchor],
   
[guide.rightAnchor constraintEqualToAnchor:bannerView.rightAnchor],
   
[guide.bottomAnchor constraintEqualToAnchor:bannerView.bottomAnchor]
 
]];
}

- (void)positionBannerViewFullWidthAtBottomOfView:(UIView *_Nonnull)bannerView {
 
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:bannerView
                                                        attribute
:NSLayoutAttributeLeading
                                                        relatedBy
:NSLayoutRelationEqual
                                                           toItem
:self.view
                                                        attribute
:NSLayoutAttributeLeading
                                                       multiplier
:1
                                                         constant
:0]];
 
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:bannerView
                                                        attribute
:NSLayoutAttributeTrailing
                                                        relatedBy
:NSLayoutRelationEqual
                                                           toItem
:self.view
                                                        attribute
:NSLayoutAttributeTrailing
                                                       multiplier
:1
                                                         constant
:0]];
 
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:bannerView
                                                        attribute
:NSLayoutAttributeBottom
                                                        relatedBy
:NSLayoutRelationEqual
                                                           toItem
:self.bottomLayoutGuide
                                                        attribute
:NSLayoutAttributeTop
                                                       multiplier
:1
                                                         constant
:0]];
}

mobileadssdk-a...@google.com

unread,
Dec 13, 2018, 6:21:34 AM12/13/18
to Ismael Machado, Google Mobile Ads SDK Developers
Hi Ismael,

Let's continue our discussion in this thread for better tracking.

Regards,
Teejay Pimentel
Mobile Ads SDK Team

--

---
You received this message because you are subscribed to the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-admob-ads-sdk/b4492a2f-2166-4389-a617-6b9eb7ec11a7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ismael Machado

unread,
Dec 13, 2018, 9:50:10 PM12/13/18
to Google Mobile Ads SDK Developers
I solved the issue on the other thread now  I just need help on this I know it says "The techniques above can easily be used for constraining to the top of the safe area by modifying the attributes and anchors used." but I am unsure of which attributes and anchors to change and exactly what value I change them to 

mobileadssdk-a...@google.com

unread,
Dec 17, 2018, 5:03:25 PM12/17/18
to Ismael Machado, Google Mobile Ads SDK Developers
Hey Ismael,

The following code snippets should help:

- (void)positionBannerViewFullWidthAtTopOfSafeArea:(UIView *_Nonnull)bannerView NS_AVAILABLE_IOS(11.0) {
  // Position the banner. Stick it to the bottom of the Safe Area.
  // Make it constrained to the edges of the safe area.
  UILayoutGuide *guide = self.view.safeAreaLayoutGuide;

  [NSLayoutConstraint activateConstraints:@[
    [guide.leftAnchor constraintEqualToAnchor:bannerView.leftAnchor],
    [guide.rightAnchor constraintEqualToAnchor:bannerView.rightAnchor],
    [guide.topAnchor constraintEqualToAnchor:bannerView.topAnchor]
  ]];
}

- (void)positionBannerViewFullWidthAtTopOfView:(UIView *_Nonnull)bannerView {
  [self.view addConstraint:[NSLayoutConstraint constraintWithItem:bannerView
                                                        attribute:NSLayoutAttributeLeading
                                                        relatedBy:NSLayoutRelationEqual
                                                           toItem:self.view
                                                        attribute:NSLayoutAttributeLeading
                                                       multiplier:1
                                                         constant:0]];
  [self.view addConstraint:[NSLayoutConstraint constraintWithItem:bannerView
                                                        attribute:NSLayoutAttributeTrailing
                                                        relatedBy:NSLayoutRelationEqual
                                                           toItem:self.view
                                                        attribute:NSLayoutAttributeTrailing
                                                       multiplier:1
                                                         constant:0]];
  [self.view addConstraint:[NSLayoutConstraint constraintWithItem:bannerView
                                                        attribute:NSLayoutAttributeTop
                                                        relatedBy:NSLayoutRelationEqual
                                                           toItem:self.topLayoutGuide
                                                        attribute:NSLayoutAttributeBottom
                                                       multiplier:1
                                                         constant:0]];
}

- Ram


=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+ page:
    http://googleadsdeveloper.blogspot.com
    https://plus.google.com/115658573333388777174/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads-sdk+unsubscrib...@googlegroups.com.

--

---
You received this message because you are subscribed to the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages