0

I'm integrating iAds for the first time. It works. What I cannot seem to do is get it at the bottom on my screen. When I do what I think is the correct math it stops showing (or rather I dont see it) but changing the position to a hardcoded value works.

// Use RootViewController manage CCEAGLView 
_viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
_viewController.wantsFullScreenLayout = YES;
_viewController.view = eaglView;

// Set RootViewController to window
if ([[UIDevice currentDevice].systemVersion floatValue] < 6.0)
{
    // warning: addSubView doesn't work on iOS6
    [window addSubview: _viewController.view];
}
else
{
    // use this method on ios6
    [window setRootViewController:_viewController];
}

// iAd
adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
CGRect adFrame = adView.frame;

adFrame.origin.y = adView.frame.size.height;
adView.frame = adFrame;
[_viewController.view addSubview:adView];

works but it shows like this: enter image description here

When I try and change the position to the bottom based upon screen height - adView height I stop seeing it.

adFrame.origin.y = _viewController.view.frame.size.height - adView.frame.size.height;

I placed break points and it seems that this should be working based upon the values for height (1024) and adView (66)

enter image description here

UPDATE: I'm now trying to init specifying a rect

adView = [[ADBannerView alloc] initWithFrame:CGRectMake(0, [[UIScreen mainScreen] bounds].size.height - adView.frame.size.height, [[UIScreen mainScreen] bounds].size.width, adView.frame.size.height)];
[adView  setDelegate:self];
[_viewController.view addSubview:adView];

Still not working, nothing shows anymore.

UPDATE 2: Trying this it does show, obviously not at the bottom

adView = [[ADBannerView alloc] initWithFrame:CGRectMake(0, 200, [[UIScreen mainScreen] bounds].size.width, 200)];

UPDATE 3: Trying this, it does show, obviously not at the bottom

adView = [[ADBannerView alloc] initWithFrame:CGRectMake(0, 200, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height)];

UPDATE 4: Trying this, works and it at the bottom, but I just made this up. Changing the 300 to 200 then nothing shows.

adView = [[ADBannerView alloc] initWithFrame:CGRectMake(0, [[UIScreen mainScreen] bounds].size.height - 300, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height)];
Jasmine
  • 15,375
  • 10
  • 30
  • 48

1 Answers1

0

Why not use initWithFrame directly when creating banner view?

I do it as below in my app and it works fine for me

 CGFloat adBannerHeight = 100.0f;

 bannerView = [[ADBannerView alloc]initWithFrame:CGRectMake(0, [[UIScreen mainScreen] bounds].size.height - adBannerHeight,[[UIScreen mainScreen] bounds].size.width,adBannerHeight)];
[bannerView setDelegate:self];
[[self view] addSubview:bannerView];

Also, Please make sure you implement all necessary delegate methods

slysid
  • 5,236
  • 7
  • 36
  • 59
  • Thanks. I tried and it is not showing. Can you look at my update above? – Jasmine Sep 07 '14 at 17:52
  • I don't see anything wrong in your code. Can you check your view hierarchy? Maybe your banner view is covered by some other view. – slysid Sep 07 '14 at 20:31
  • adView = [[ADBannerView alloc] initWithFrame:CGRectMake(0, [[UIScreen mainScreen] bounds].size.height - adView.frame.size.height, [[UIScreen mainScreen] bounds].size.width, adView.frame.size.height)]; In your code adView.frame.size.height will be zero as the adView is still not generated.So you ad banner view is set below the UIWindow bounds. Set it to some hard value like 100 or 150. – slysid Sep 07 '14 at 20:33
  • Try Like this adView = [[ADBannerView alloc] initWithFrame:CGRectMake(0, [[UIScreen mainScreen] bounds].size.height -100, [[UIScreen mainScreen] bounds].size.width, 100)]; – slysid Sep 07 '14 at 20:35
  • OK, see Update #2 and Update #3. Trying your line it doesn't show, but doing the line in my update it does. – Jasmine Sep 07 '14 at 21:25
  • Update #4 works, but the 300 is hardcoded, changing to 200 then nothing shows. Its obvious it is getting pushed off screen. I wonder if I should hardcode `adView` sizing based upon device resolution just to make this work. – Jasmine Sep 07 '14 at 21:36
  • In the my experience, that is the better way.See my updated answer, define the height before and use it in your geometry calculations. In your update 4, your are setting the wrong height – slysid Sep 07 '14 at 21:39
  • adding these 2 lines solves everything completely, also using your code. `adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierLandscape]; adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;` – Jasmine Sep 07 '14 at 21:46