调整iAd横幅视图的大小
这看起来应该很简单,但是文档尚不清楚.在简介中在ADBannerView
类中,Apple这样说:
This seems like it should be simple, but the documentation is very unclear. In the introduction of the ADBannerView
class, Apple says this:
横幅视图必须始终使用在中定义的标准尺寸之一 内容大小标识符.这是为了确保广告是 正确绘制.您配置横幅视图的
requiredContentSizeIdentifiers
属性以及一组可能的大小 您的视图被允许在您的应用程序中使用.改变尺寸 横幅视图,请勿直接设置范围;而是设置currentContentSizeIdentifier
属性为大小标识符之一 包含在该集合中.您可以检索 特定标识符等同于在特定设备上通过调用sizeFromBannerContentSizeIdentifier:
类方法.
A banner view must always use one of the standard sizes defined in Content Size Identifiers. This is to ensure that the advertisement is drawn correctly. You configure the banner view’s
requiredContentSizeIdentifiers
property with the set of possible sizes your view is allowed to use in your application. To change the size of the banner view, do not set the bounds directly; instead set thecurrentContentSizeIdentifier
property to one of the size identifiers included in that set. You can retrieve the actual dimensions that a particular identifier equates to on a specific device by calling thesizeFromBannerContentSizeIdentifier:
class method.
但是,从iOS 6开始,这些方法在文档中都标记为已弃用:
However, these methods are all marked in the documentation as deprecated since iOS 6:
弃用声明:横幅视图不再使用内容大小 身份标识.有关详细信息,请参见内容大小标识符.
Deprecation Statement: Banner views no longer use content size identifiers. See Content Size Identifiers for details.
如果您访问,除了这些常量的文档(自iOS 6起全部标记为已废弃),什么都找不到.
If you go to "Content Size Identifiers", nothing can be found except the documentation for these constants, all marked as depricated since iOS 6. The rest of the documentation doesn't seem to be any help either.
如果不赞成使用这些方法,并且似乎什么都没有取代,那么如何调整iAd标语的大小并获得其尺寸?
If these methods are deprecated, and nothing seems to have taken their place, how are you supposed to resize and get the size of iAd banners?
无需设置ADBannerView
的大小.您的ADBannerView
将知道它在哪个设备上并正确设置其尺寸.您需要做的只是设置ADBannerView
的位置.查看此实现作为示例.
There's no need to set the ADBannerView
's size. Your ADBannerView
will know which device it is on and set the dimensions of itself correctly. All you need to do is set the ADBannerView
's position. Check this implementation for an example.
如果您使用的是自动版式,并且希望ADBannerView
位于屏幕底部,请使用Bottom Space to: Bottom Layout Guide
将其固定在屏幕底部,并将其与Align Center X to: Superview
对齐.确保您不要设置任何高度,宽度,尾随或前导约束
If you're using Auto Layout and wanted the ADBannerView
to be at the bottom of the screen then pin it to the bottom of the screen with Bottom Space to: Bottom Layout Guide
and align it to Align Center X to: Superview
. Be sure you do not set any height, width, trailing, or leading constraints