gpt4 book ai didi

ios - iAd 定位不正确

转载 作者:行者123 更新时间:2023-11-28 09:13:41 26 4
gpt4 key购买 nike

我正在使用 SpriteKit 开发一款游戏,我想实现 iAd。在我的应用程序启动后,横幅看起来不错,只是它覆盖了我的 View ,如此处所示 http://i.imgur.com/O9Gc6o6.png

在我将 iPhone 的方向更改为横向后,横幅消失了。当我将方向改回纵向时它再次出现但它的位置发生了变化:http://i.imgur.com/K3AqGl4.png

从此时开始,横幅在方向更改为横向后可见,但也发生了移动。

这是我在 UIViewController 中的代码:

self.canDisplayBannerAds = true
adBanner = ADBannerView(frame: CGRect.zeroRect)
adBanner.delegate = self
adBanner.hidden = true
adBanner.frame.origin = CGPointMake(0.0, self.view.bounds.size.height - adBanner.frame.size.height)
self.view.addSubview(adBanner)

真正奇怪的是,这种位置移动只发生在我的 iPhone 上。在模拟器中测试过 - 没问题。 Buddy 在他的 iPhone 上进行了测试 - 没问题。不过一开始遮住 View 还是发生了。

这是怎么回事?我没主意了。在过去的几个小时里,我试图在谷歌上找到它,但没有成功。提前致谢。

最佳答案

iOS 9.2.1,Xcode 7.2.1,启用 ARC

在 iPhone 的设置中检查 iAd 的开发者设置。

根据我的经验,问题出在 self.canDisplayBannerAds = true 上,然后更改 adBanner 的框架而没有正确修改它,这就是您遇到麻烦的地方。

在所有 Apple 示例中,他们从未设置此属性,您可以自己查看:

https://developer.apple.com/library/ios/samplecode/iAdSuite_Storyboard/Listings/BasicBanner_BasicBanner_TextViewController_m.html#//apple_ref/doc/uid/DTS40013458-BasicBanner_BasicBanner_TextViewController_m-DontLinkElementID_6

我在为 adBanner 设置动画以在广告加载后升起时遇到此问题,或遇到类似此行为的问题。我认为这与此有很大关系......

To ensure that advertisements are displayed properly, a banner view must always be sized to match one of the built-in advertising sizes. The ADBannerView class enforces this by preventing you from changing the frame directly. Instead, you change a banner view’s frame by setting the currentContentSizeIdentifier property. Changing the value stored in this property resizes the banner view’s frame to the match the size for the provided identifier. Before you can set a particular size identifier, the size identifier must also be included in the set of size identifiers included in the requiredContentSizeIdentifiers property.

本文档的其余部分在这里,如果你好奇的话:

https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/iAd_Guide/BannerAdvertisements/BannerAdvertisements.html#//apple_ref/doc/uid/TP40009881-CH3-SW2

从我在开头链接的 Apple“Basic Banner”示例中,他们通过首先访问广告横幅的 sizeThatFits 属性来玩弄横幅框架:

// all we need to do is ask the banner for a size that fits into the layout area we are using
CGSize sizeForBanner = [self.bannerView sizeThatFits:contentFrame.size];

设置self.canDisplayBannerAds 后,将发生以下情况:

取自 UIViewController(iAdAdditions)

...When a view controller enables banner ads, the system puts the view controller’s content view inside of a new content view that the system manages. This allows the system to dynamically resize the original content view when a banner ad is displayed, as well as managing the display of the banner ad itself. This property provides access to the original content view, rather than the containing view that manages banner ad display.

If banner ad display has not been enabled for a view controller, this property returns the content view.

If banner ad display is enabled and then later disabled for a view controller, the system-managed content view is not removed.

希望这对您有所帮助。干杯!

关于ios - iAd 定位不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28456568/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com