我想将ADInterstitialAd
视为常规UIView,以便在使用时获得一些灵活性。
例如,默认的插页式转换为slide up from the bottom of the screen
。我不喜欢那样。是否可以首先将alpha值修改为0,然后将其更改为1?
另一个例子是在全屏添加前面有不同的UIView少量时间,即仅在ADInterstitialAd
的转换过程中? ADInterstitialAd
往往是视图层次结构中最顶层的视图。如果我设法将ADInterstitialAd
视为常规UIView,我想我可以这样做。有关如何实现这一目标的任何建议吗?
答案 0 :(得分:3)
您可以设置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
继承而且有明确的方法需要调用才能呈现它们(presentInView:
和presentFromViewController:
)。因此,没有公共API来控制这些广告的展示方式(这可能是故意这样做的,以便Apple可以保证向用户展示广告)。
答案 1 :(得分:1)
我没有这方面的经验,但是看documentation您应该能够创建自己的视图,使用presentInView:
,并在该视图上执行您想要的任何动画。