键盘盖ipAd,怎么修复?

时间:2014-12-30 16:25:17

标签: ios autolayout iad

我在一两个星期前发了帖子,到目前为止还没有人有答案,所以我打算尝试另一种方法。当我在iOS视图控制器上使用canDisplayBannerAds时,底部会显示横幅广告。这对我的应用程序来说是无用的,因为键盘始终存在并且它涵盖了iAd。我也不能在InterfaceBuilder中添加iAd,因为我并不总是希望显示广告,如果删除它们,在InterfaceBuilding中添加它们会破坏自动布局。因此,我在地球上如何显示键盘未覆盖的横幅广告?

1 个答案:

答案 0 :(得分:1)

首先,您需要知道键盘何时出现,并在此时刻设置iAd的帧。 所以,这是代码。 首先,您需要实现观察者:

    [[NSNotificationCenter defaultCenter] addObserver:self 
                                     selector:@selector(keyboardDidShow:)
                                         name:UIKeyboardDidShowNotification
                                       object:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                     selector:@selector(keyboardDidHide:)
                                         name:UIKeyboardDidHideNotification
                                       object:nil];    

以及在apears时要执行的方法:

    - (void)keyboardDidShow: (NSNotification *) notification{
    // Here we will set the frame of the banner at the top of the keyboard


        if (_bannerIsVisible)
         {

         [UIView beginAnimations:@"animateAdBannerOn" context:NULL];
         // Assumes the banner view is just off the bottom of the screen.
         banner.frame =CGRectMake(0, self.view.frame.size.height-266, 320, 50);

         [UIView commitAnimations];
        }
    }

    - (void)keyboardDidHide: (NSNotification *) notification{
    // Here we will set the frame of the banner at the bottom of the view
        if (_bannerIsVisible)
         {

         [UIView beginAnimations:@"animateAdBannerOn" context:NULL];
         // Assumes the banner view is just off the bottom of the screen.
         banner.frame =CGRectMake(0, self.view.frame.size.height-50, 320, 50);

         [UIView commitAnimations];
        }
    }

也许您需要调整大小或动画才能看起来不错。 对不起我的英文希望这对你有所帮助。