Sizing iAd Banner Views

2019-07-29 19:42发布

问题:

This seems like it should be simple, but the documentation is very unclear. In the introduction of the ADBannerView class, Apple says this:

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 the currentContentSizeIdentifier 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 the sizeFromBannerContentSizeIdentifier: class method.

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.

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.

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?

回答1:

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.

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



回答2:

OK. I still have no idea about resizing, but I figured out initial sizing.

Since iOS 6, ADBannerViews have an adType property. This property can be either ADAdTypeBanner or ADAdTypeMediumRectangle. The documentation gives the sizes for both kinds: The banner height varies with device type and orientation as follows:

UI Idiom and Orientation   | Ad Height
--------------------------------------
phone, portrait            | 50 points
phone, landscape           | 32 points
pad, portrait or landscape | 66 points

As for resizing, I can only assume that the banner view automatically takes the width of the screen by observing orientation change notifications.



标签: ios iad