3

I am currently adding iAd banners into my SpriteKit game, and I have successfully got the ads showing. But when I go to remove the banner by pushing it off the bottom it does not move, even though it is the exact opposite to the code to get it to appear.

This is the function, which is called from a notification observer:

func hideBannerAd(notification:NSNotification)
{
    if bannerAdVisible == true
    {
        println(bannerAd.frame);

        UIView.beginAnimations("hideAd", context: nil);
        bannerAd.frame = CGRectOffset(bannerAd.frame, 0, bannerAd.frame.size.height);
        println(bannerAd.frame);
        UIView.commitAnimations()
        bannerAdVisible = false
        bannerAd.cancelBannerViewAction()
    }
}

The 2 println statements produce the following:

(0.0, 1024.0, 768.0, 66.0)

(0.0, 1090.0, 768.0, 66.0)

So the position of the banner is being changed, but it is not shown on the screen.

If you know the problem, I would be grateful for a little help.

EDIT I will add that the hideBannerAd and all of the code to do with the ad is in the GamveViewController.

Antony
  • 199
  • 1
  • 12
  • 1
    first: where is that function called from? from the main/ui thread? second: are you using auto layout? – luk2302 Jun 22 '15 at 18:25
  • 1
    If the `frame` is being updated but the view doesn't change, you may be calling this method on a background thread. Also, stylistically, I suggest you remove the old iOS 3-style animation syntax. – Aaron Brager Jun 22 '15 at 18:27
  • It is being called from a NSNotificationCenter observer from a separate SKScene and the function is in the GameViewController class. I don't think I am using auto layout as I have done it all in code and there is nothing to do with auto layout there. – Antony Jun 22 '15 at 18:31
  • Try executing this code from main thread, in `viewdidload` for example and tell us if it did work. If it did, the problem is what @AaronBrager said – aramusss Jun 25 '15 at 13:06
  • @OnlyAntony Notification methods are called on the thread from which they're posted. You can use `dispatch_async` or `NSOperation` to switch to the main queue. – Aaron Brager Jun 25 '15 at 17:06
  • I have just found the solution! Previously I had the show banner function call in the `viewWillLayoutSubViews` function with a load of other code, when @aramusss mentioned the `viewDidLoad` I moved it there and now it works! Thank you all for your help :D – Antony Jun 26 '15 at 08:29

1 Answers1

0

Problem Solved!

With the assistance from @aramusss comment I have found that I was calling the function to show the banner in the viewWIllLayoutSubViews function, so I moved it to the viewDidLoad function and it now works!

Thank you all for your help!

Antony
  • 199
  • 1
  • 12