Скрытие горизонтальных баннеров iAd в skscene

У меня есть контроллер представления с именем ViewController, в котором у меня есть два метода: hideAd и 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];

}

// Метод вызывается, когда iAd не загружается.

-(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];

}

Я хотел бы иметь возможность вызывать эти методы из моих skscene, две из которых называются startview и gameview. Я попытался реализовать это решение: Как показать iAd на одной SKScene и скрыть на другой, но setDelegate у меня не работает. Как я могу скрыть и показать свой баннер iads?


person maxhud    schedule 15.03.2014    source источник


Ответы (1)


Вместо того, чтобы связывать альфу, измените ее положение.

-(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];
    }

}
person Guru    schedule 15.03.2014
comment
Правильно ли добавить это в мой viewcontroller.h? {-(void)hideBannerView; -(void)showBannerView; @property (strong, nonatomic) IBOutlet ADBannerView *adBannerView;} И что такое add_dsp? где сделать рекламный баннер видимым BOOL? Это также говорит мне, что .size не является свойством viewcontroller. - person maxhud; 15.03.2014
comment
удалить app_dsp, ваш баннер сверху или снизу? если сверху, то держите содержимое внутри цикла if, если снизу, используйте блок else. Вы можете использовать bool в том же классе... см. этот пример чтобы добавить iad в cocos2d"> stackoverflow.com/questions/17815777/how-to-add-iad-in-cocos2d/ - person Guru; 15.03.2014