I've been looking at various tutorials and code snippets, try to implement iAd. I've been successful to an extent but I need to customise, I can't seem to work out what I need to do to make my changes, can anyone help?
- (void)viewDidLoad
{
adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.frame = CGRectOffset(adView.frame, 0, -50);
adView.requiredContentSizeIdentifiers = [NSSet setWithObjects:ADBannerContentSizeIdentifierPortrait, ADBannerContentSizeIdentifierLandscape, nil];
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
[self.view addSubview:adView];
adView.delegate = self;
self.bannerIsVisible = NO;
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!self.bannerIsVisible)
{
[UIView beginAnimations:@"animateAdBannerOn" context:NULL];
// banner is invisible now and moved out of the screen on 50 px
banner.frame = CGRectOffset(banner.frame, 0, 50);
[UIView commitAnimations];
self.bannerIsVisible = YES;
}
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
if (self.bannerIsVisible)
{
[UIView beginAnimations:@"animateAdBannerOff" context:NULL];
// banner is visible and we move it out of the screen, due to connection issue
banner.frame = CGRectOffset(banner.frame, 0, -50);
[UIView commitAnimations];
self.bannerIsVisible = NO;
}
}
As it stands, the banners are loaded at the top of a UIWebView. Firstly I'd like it at the bottom and secondly, the ad overlaps the WebView content, is there any way I can push the WebView when an ad loads or disappears?
I'd appreciate any help, this is driving round the bend!
Thanks.
Use this code instead of
and change Ad placement (375.0) according to what you want :)
set adview.frame.origin.y to however far bottom you want it, when you want it. For instance, my iad is setup in the app delegate, then in the view controller I want, in viewwillapear, I'd use adview.frame.origin.x = 0;adview.frame.origin.y = 420; [SharediAdView setframe:adview.frame];
with diff settings depending on iphone 3.5inch/4inch, space in the current view controller, & orientation.
If you'd rather move everything up/down, and don't want to mess with a tailored solution, I'd try this stuff: https://github.com/chrisjp/CJPAdController