iAd插页式广告的自定义过渡(iAd custom transition for interstitial ads)

编程入门 行业动态 更新时间:2024-10-17 09:50:09
iAd插页式广告的自定义过渡(iAd custom transition for interstitial ads)

我想将ADInterstitialAd作为普通的UIView来使用,以获得一些灵活性。

例如,默认的插页式过渡slide up from the bottom of the screen 。 我不喜欢那样。 是否有可能首先将alpha值修改为0,然后将其更改为1?

另一个例子是在全屏添加前添加不同的UIView一小段时间,也就是在ADInterstitialAd过渡过程中? ADInterstitialAd往往是视图层次结构中最顶层的视图。 我想我可以做到这一点,如果我设法把ADInterstitialAd作为一个普通的UIView。 有关如何实现这一目标的任何建议?

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?

最满意答案

您只需制作AdBannerView的Alpha值即可获得您想要的效果:

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 } }

这是另一种可以呈现bannerView的方式。 当广告完成向上滑动时,您可以移除广告顶部的视图:

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 } }

编辑:

至于ADInterstitialAd ,那些似乎从NSObject继承,并有显式的方法,你需要调用,以呈现它们( presentFromViewController:和presentFromViewController: 。 因此,没有公开API来控制这些广告的呈现方式(这可能是有目的地完成的,以便Apple可以保证向用户展示广告)。

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).

更多推荐

本文发布于:2023-04-29 01:20:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1334496.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:插页   自定义   广告   iAd   ads

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!