Customized iAd Transition for Interstitials

I would like to consider ADInterstitialAd as a regular UIView to get some flexibility in using them.

For example, the default interstitial transition is slide up from the bottom of the screen . I do not like it. Can I change the alpha value to 0 first, and then change it to 1?

Another example is to have a different UIView before adding fullscreen for a short period of time, namely only during the ADInterstitialAd transition ADInterstitialAd ? ADInterstitialAd tend to be the highest view in view hierarchies. I suppose I can do this if I manage to handle ADInterstitialAd as a regular UIView. Any suggestions on how to achieve this?

+5
source share
2 answers

You can simply animate the alpha value of your AdBannerView to achieve the desired effect:

 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 to present bannerView. You can remove the top view of the ad when it has finished crawling:

 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 ADInterstitialAd s, they seem to inherit from NSObject and have explicit methods that must be called to represent them ( presentInView: and presentFromViewController: . Therefore, there is no public API to control the presentation of these ads (this is most likely done on purpose so that Apple can guarantee that the ad will be shown to the user).

+3
source

I have no experience with this, but looking at the documentation , you can create your own view, use presentInView: and do whatever animation you need in this view.

+1
source

Source: https://habr.com/ru/post/1242174/


All Articles