0

I have a view controller called ViewController in which I have two methods, hideAd and showAd:

// Method is called when the iAd is loaded.
-(void)showAd:(ADBannerView *)banner {

// Creates animation.
[UIView beginAnimations:nil context:nil];

// Sets the duration of the animation to 1.
[UIView setAnimationDuration:1];

// Sets the alpha to 1.
// We do this because we are going to have it set to 0 to start and setting it to 1 will cause the iAd to fade into view.
[banner setAlpha:1];

//  Performs animation.
[UIView commitAnimations];

}

// Method is called when the iAd fails to load.

-(void)hideAd:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {

// Creates animation.
[UIView beginAnimations:nil context:nil];

// Sets the duration of the animation to 1.
[UIView setAnimationDuration:1];

// Sets the alpha to 0.
// We do this because we are going to have it set to 1 to start and setting it to 0 will cause the iAd to fade out of view.
[banner setAlpha:0];

//  Performs animation.
[UIView commitAnimations];

}

I would like to be able to call these methods from my skscenes, two of which called startview and gameview. I tried implemeting this solution: How to show iAd on a certain SKScene and hide it on the other one, but setDelegate does not work for me. In what way can I hide and show my banner iads?

Community
  • 1
  • 1
Max Hudson
  • 9,961
  • 14
  • 57
  • 107

1 Answers1

0

Instead of chaining alpha, move its position.

-(void)showBannerView
{
    if (_adBannerViewIsVisible)
    {
        return;
    }


    if (_adBannerView)
    {
        _adBannerViewIsVisible = true;

        CGRect frame = _adBannerView.frame;

        if(app_dsp.isBannerOnTop)
        {
            frame.origin.x = 0.0f;
            frame.origin.y = -_adBannerView.frame.size.height;

        }
        else
        {
            frame.origin.x = 0.0f;
            frame.origin.y = self.size.height;// - _adBannerView.frame.size.height;
        }


        _adBannerView.frame = frame;

        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.5];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];


        if(app_dsp.isBannerOnTop)
        {
            frame.origin.x = 0.0f;
            frame.origin.y = 0.0f;
        }
        else
        {
            frame.origin.x = 0.0f;
            frame.origin.y = self.size.height - _adBannerView.frame.size.height;
        }

        _adBannerView.frame = frame;

        [UIView commitAnimations];
    }

}



-(void)hideBannerView
{
    if (!_adBannerViewIsVisible)
    {
        return;
    }

    if (_adBannerView)
    {
        _adBannerViewIsVisible = false;


        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.5];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

        CGRect frame = _adBannerView.frame;

        if(app_dsp.isBannerOnTop)
        {
            frame.origin.x = 0.0f;
            frame.origin.y = -_adBannerView.frame.size.height ;
        }
        else
        {
            frame.origin.x = 0.0f;
            frame.origin.y = self.size.height ;
        }

        _adBannerView.frame = frame;

        [UIView commitAnimations];
    }

}
Guru
  • 21,652
  • 10
  • 63
  • 102
  • Is it correct to add this to my viewcontroller.h? {-(void)hideBannerView; -(void)showBannerView; @property (strong, nonatomic) IBOutlet ADBannerView *adBannerView;} Also what is add_dsp? where do I make the adbannerviewisvissible BOOL? It is also telling me that .size is not a property of viewcontroller. – Max Hudson Mar 15 '14 at 11:23
  • remove app_dsp, your banner is on top or bottom? if top then keep content inside if loop, if bottom then use else block. You can use bool in same class...see this sample http://stackoverflow.com/questions/17815777/how-to-add-iad-in-cocos2d/17816415#17816415 – Guru Mar 15 '14 at 14:44