5

I would like to treat ADInterstitialAds as a regular UIView's to gain some flexibility in their usage.

For example, the default interstitial transition is slide up from the bottom of the screen. I don't like that. Is it possible to modify the alpha value to be 0 at first and than change it to 1?

Another example is having different UIView in front of the fullscreen add for a small amount of time, namely just during transition process of the ADInterstitialAd? ADInterstitialAds tend to be the topmost view in view hierarchies. I imagine I could do this if I manage to treat ADInterstitialAds as a regular UIView. Any suggestions on how to achieve this?

Mark
  • 7,167
  • 4
  • 44
  • 68
potato
  • 4,479
  • 7
  • 42
  • 99

2 Answers2

3

You could just animate the alpha value of your AdBannerView to achieve the effect you want:

import iAd

private var bannerView: AdBannerView!

override func viewDidLoad() {
    super.viewDidLoad()

    // Create your banner view however you want, and add it to your UI.
    bannerView = AdBannerView()
    bannerView.alpha = 0
    addSubview(bannerView)
}

// When you want to show the ad, animate the alpha.
private func animateInAd(appearing: Bool) {
    UIView.animateWithDuration(1.0) [weak self] {
        self?.bannerView.alpha = appearing ? 1 : 0
    }
}

Here is another way you can present bannerView. You can remove the view on top of the ad when it has finished sliding up:

import iAd

private var coverView: UIView!
private var bannerView: AdBannerView!

override func viewDidLoad() {
    super.viewDidLoad()

    // Create your banner view however you want, and add it to your UI.
    bannerView = AdBannerView()   
    addSubview(bannerView)

    // Create the cover view however you want, and add it above the banner view.
    coverView = UIView()
    addSubview(coverView)
}

private func animateInAd(appearing: Bool) {
    let hideAdPosition = view.frame.size.height        
    let showAdPosition = hideAdPosition - bannerView.frame.size.height

    UIView.animateWithDuration(1.0, animations: [weak self] {
        self?.bannerView.frame.origin.y = appearing ? showAdPosition : hideAdPosition
    }) { [weak self] success in
        self?.animateCover(appearing: !appearing)
    }
}

private func animateCover(appearing: Bool) {
    UIView.animateWithDuration(1.0) [weak self] {
        self?.coverView.alpha = appearing ? 1 : 0
    }
}

EDIT:

As for ADInterstitialAds, those seem to inherit from NSObject and have explicit methods you need to call in order to present them (presentInView: and presentFromViewController:). Therefore, there is no public API to control how these ads are presented (This is likely done on purpose so that Apple can guarantee that the ad is shown to the user).

Mark
  • 7,167
  • 4
  • 44
  • 68
  • oh nice. what about interstitial? – potato Feb 16 '16 at 11:44
  • Can you provide more information about the second scenario? Do you mean to have a second view on top of the banner view? And then apply an alpha transition to it? – Mark Feb 16 '16 at 12:45
  • I've updated my answer to include code for what I believe you are asking in the second part of your question. – Mark Feb 16 '16 at 14:32
  • thank you! these are pretty good ways of animation banner ads. they will definitively come handy. The question was actually about interstitial ads- the full screen ads. This is the link do developer library https://developer.apple.com/library/ios/documentation/iAd/Reference/UIViewController_iAd_Additions/. These ads tend to always slide up form the bottom of the screen and fill the entire screen space. – potato Feb 16 '16 at 15:08
  • Ah gotcha. I'll take a look at that later today. – Mark Feb 16 '16 at 15:10
  • Answer updated. Unfortunately it looks like there are not customization points for presenting `ADInterstitialAd`s. – Mark Feb 16 '16 at 17:36
1

I have no experience with this but looking at the documentation you should be able to create your own view, use presentInView:, and perform whatever animation you want on that view.

EmilioPelaez
  • 18,758
  • 6
  • 46
  • 50