Animations not holding after iAd is pressed - ios

So, I am trying to implement iAds into my application, but I cannot get it to work properly.
I am using these two functions to show and hide the banner and it works great:
- (void)showAdBanner:(ADBannerView *)banner {
if (bannerVisible) return;
NSLog(#"showing ad");
[UIView beginAnimations:#"animateBannerIn" context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[banner setFrame:CGRectOffset([banner frame], 0, -bannerHeight)];
[toolbarView setFrame:CGRectOffset([toolbarView frame], 0, -bannerHeight)];
[UIView commitAnimations];
bannerVisible = YES;
}
- (void)hideAdBanner:(ADBannerView *)banner {
if (!bannerVisible) return;
NSLog(#"hiding ad");
[UIView beginAnimations:#"animateBannerOut" context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[banner setFrame:CGRectOffset([banner frame], 0, bannerHeight)];
[toolbarView setFrame:CGRectOffset([toolbarView frame], 0, bannerHeight)];
[UIView commitAnimations];
bannerVisible = NO;
}
The only issue is that after one presses on the iAd banner, the toolbar view returns to its original position sans-iAd.
I have removed all layout constraints and it still is occurring. I can attach a video after if it clarifies.
Thank you
Video: https://www.dropbox.com/s/64mbiowk94sl6rq/iAdIssue.mov

Related

Hide iAd view on pressing a button

I can't find the right solution to hide my iAd view when I press a button.
I am loding iAd view like this:
-(void)bannerViewDidLoadAd:(ADBannerView *)banner
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[banner setAlpha:1];
[UIView commitAnimations];
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[banner setAlpha:0];
[UIView commitAnimations];
}
It works perfect. But how would i hide my iAd view if I don't want to show one?
I was searching for answer here, but there was no direct answer.
If the user doesn't have internet connection the banner will be blank. It is required by apple for the banner to be hidden when internet connection is not availble.
Consider you are creating this way,
- (void)createAdBannerView {
Class classAdBannerView = NSClassFromString(#"ADBannerView");
if (classAdBannerView != nil) {
self.adBannerView = [[[classAdBannerView alloc]
initWithFrame:CGRectZero] autorelease];
[_adBannerView setRequiredContentSizeIdentifiers:[NSSet setWithObjects:
ADBannerContentSizeIdentifier320x50,
ADBannerContentSizeIdentifier480x32, nil]];
if (UIInterfaceOrientationIsLandscape([UIDevice currentDevice].orientation)) {
[_adBannerView setCurrentContentSizeIdentifier:
ADBannerContentSizeIdentifier480x32];
} else {
[_adBannerView setCurrentContentSizeIdentifier:
ADBannerContentSizeIdentifier320x50];
}
[_adBannerView setFrame:CGRectOffset([_adBannerView frame], 0,
-[self getBannerHeight])];
[_adBannerView setDelegate:self];
[self.view addSubview:_adBannerView];
}
}
call [self.adBannerView removeFromSuperview]; when and were you need to hide.
#Matiass21, write the below code here _bannerIsVisible is bool value and _adBanner is ADBannerView object.
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!_bannerIsVisible)
{
// If banner isn't part of view hierarchy, add it
if (_adBanner.superview == nil)
{
[self.view addSubview:_adBanner];
}
[UIView beginAnimations:#"animateAdBannerOn" context:NULL];
// Assumes the banner view is just off the bottom of the screen.
banner.frame = CGRectOffset(banner.frame, 0, -banner.frame.size.height);
[UIView commitAnimations];
_bannerIsVisible = YES;
}
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
NSLog(#"Failed to retrieve ad");
if (_bannerIsVisible)
{
[UIView beginAnimations:#"animateAdBannerOff" context:NULL];
// Assumes the banner view is placed at the bottom of the screen.
banner.frame = CGRectOffset(banner.frame, 0, banner.frame.size.height);
[UIView commitAnimations];
_bannerIsVisible = NO;
}
}

iAds on 3.5 Iphone not appearing

I have set up iAds for my app, but for whatever reason, they only appear on the iphone 4 inch and not the 3.5 inch. First, I thought it had something to do with the Auto Layout, so I made sure the BannerView appeared in both screen sizes. After doing so, I ran and still would not work.
Here is the code I used to tell the bannerView what to do. This is in the ViewController.m file.
#pragma mark iAd Delegate Methods
-(void)bannerViewDidLoadAd:(ADBannerView *)banner {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[banner setAlpha:1];
[UIView commitAnimations];
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[banner setAlpha:0];
[UIView commitAnimations];
}
Also, this is being done in Spritekit if that matters.
Thanks for helping, and I'm pretty new to coding so something that may seem obvious, I might have easily not noticed.
You cannot animate the alpha of an object. Alternatively, you should be modifying it's transparency via it's opacity:
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
[UIView animateWithDuration:1.0 animations:^{
banner.layer.opacity = 1.0f;
}];
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
[UIView animateWithDuration:1.0 animations:^{
banner.layer.opacity = 0.0f;
}];
}

iAd how to hide and show ads at a specifc point in my app

my goal is to have my iAd show at the main menu screen(which I already accomplished) but when the user push a button to start the game I want the ad to go away and when the game ends the ad to reappear...I saw a lot of other similar questions but none had answers(searched for hours :/ ). also checked the documentation and couldn't find a logical solution, I'm also a newbie,thanks!
*update the code im working with .h file
-(void) bannerViewDidLoadAd:(ADBannerView *)banner
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[banner setAlpha:1];
[UIView commitAnimations];
}
-(void) bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[banner setAlpha:0];
[UIView commitAnimations];
}

iAd displays a white line when content is unavailable?

My advertisement banner is replaced with a white banner when there is no content to display. Is there any reason for this based on the code provided? Also, is there anyway to properly supplement the banner with AdMob when iAd is unavailable?
//iAd Advertising
#pragma mark iAd Delegate Methods
- (void) bannerViewDidLoadAd:(ADBannerView *)banner {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[banner setAlpha:1];
[UIView commitAnimations];
}
- (void) bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[banner setAlpha:1];
[UIView commitAnimations];
advertisement.hidden = YES;
}
I had tried this as far as supplementing it with Google AdMob:
#pragma mark iAd Delegate Methods
- (void) bannerViewDidLoadAd:(ADBannerView *)banner {
advertisement.hidden = NO;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[banner setAlpha:1];
[UIView commitAnimations];
bannerView_.hidden = YES;
} // if there is an internet connection, load the iAd with a 1 second fade in effect
- (void) bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
//MAKE SURE THIS IS RIGHT OR FIGURE OUT HOW TO MAKE IT RIGHT
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[banner setAlpha:1];
[UIView commitAnimations];
advertisement.hidden = YES;
//2
bannerView_.hidden = NO;
bannerView_ = [[GADBannerView alloc]initWithFrame:CGRectMake(0, 20, 320, 50)];
bannerView_.adUnitID = #"//ca-app-pub-";
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];
[bannerView_ loadRequest:[GADRequest request]];
}
Was I wrong to make outlets of the bannerviews and have them hidden or shown? It doesn't work, it always only shows one of the advertisements, and as stated before, when iAd isn't there it only shows a white banner with nothing in it, which is intrusive and not cosmetic for the app's purpose.
Based on this, what have I done wrong? For both cases that is, why does the iAd show a white banner, and why does the AdMob not supplement itself.
In StoryBoard, set your banner to hidden.
In your viewController (the one define as delegate for the banner), put this code :
- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
[banner setHidden:false];
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
NSLog(#"Error : %#",error.description);
[banner setHidden:true];
}
If you set the alpha to 0 in storyboards, this will allow your code you've already used to work. Had the same problem.
It looks like in didFailToReceiveAdWithError: you should be animating the banner alpha to zero but you're actually animating it to one.

UIView transitionFromView change view heigh

I am using this code to change between 2 UIView:
UIViewAnimationOptions animationType = UIViewAnimationOptionTransitionFlipFromLeft;
[UIView transitionFromView:self.playlistTableView toView:self.playerView duration:0.5 options:animationType completion:^(BOOL finished){
[self.containerView sendSubviewToBack:self.upperView];
[self.containerView sendSubviewToBack:self.playerView];
self.isPlaylistVisible = !self.isPlaylistVisible;
isControlsHidden = NO;
}];
And i noticed a strange behavior, that when i made the flip the height of the self.playerView loosing 20px and after one second it's increase back to the normal frame size.
I try to change the animationType to UIViewAnimationOptionLayoutSubviews and now when i change between the view this behavior is not occur.
Any idea what can be the issue?
Please try this code.
[self.upperView setHidden:YES];
[self.playerView setHidden:NO];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:containerView cache:YES];
[UIView setAnimationDuration:1.0];
[UIView commitAnimations];
[containerView addSubview:self.playerView];
For getting reverse case
[self.upperView setHidden:NO];
[self.playerView setHidden:YES];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:containerView cache:YES];
[UIView setAnimationDuration:1.0];
[UIView commitAnimations];
[containerView addSubview:self.upperView];

Resources