【问题标题】:iAd custom transition for interstitial ads用于插页式广告的 iAd 自定义过渡
【发布时间】:2016-02-03 09:40:07
【问题描述】:

我想将ADInterstitialAds 视为常规 UIView,以便在使用时获得一些灵活性。

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

另一个例子是在全屏前添加不同的 UIView 一小段时间,即只是在 ADInterstitialAd? 的转换过程中。 ADInterstitialAds 往往是视图层次结构中最顶层的视图。我想如果我设法将ADInterstitialAds 视为常规 UIView,我可以做到这一点。关于如何实现这一点的任何建议?

【问题讨论】:

  • 温馨提醒,iAD 将于 2016 年 6 月被 Apple 关闭..
  • 谢谢!没有意识到这一点。并且替换将由 Apple 提供?
  • 这里没有替代品.. developer.apple.com/news/?id=01152016a

标签: ios uiview iad interstitial


【解决方案1】:

您可以为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
    }
}

编辑:

至于ADInterstitialAds,它们似乎继承自NSObject,并且具有您需要调用以显示它们的显式方法(presentInView:presentFromViewController:)。因此,没有公共 API 来控制这些广告的呈现方式(这很可能是故意这样做的,以便 Apple 可以保证向用户展示广告)。

【讨论】:

  • 哦,太好了。插页式广告呢?
  • 你能提供更多关于第二种情况的信息吗?你的意思是在横幅视图的顶部有第二个视图吗?然后对其应用 alpha 过渡?
  • 我已更新我的答案,以包含我认为您在问题的第二部分中提出的问题的代码。
  • 谢谢!这些都是很好的动画横幅广告方式。他们肯定会派上用场。问题实际上是关于插页式广告——全屏广告。这是开发人员库developer.apple.com/library/ios/documentation/iAd/Reference/… 的链接。这些广告往往总是从屏幕底部向上滑动并填满整个屏幕空间。
  • 啊,明白了。今天晚些时候我会看看那个。
【解决方案2】:

我没有这方面的经验,但是看着documentation,您应该能够创建自己的视图,使用presentInView:,并在该视图上执行您想要的任何动画。

【讨论】:

    猜你喜欢
    • 2016-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多