@@ -45,6 +45,7 @@ import WebKit
45
45
46
46
// only webView.scrollView should retain adView as subView
47
47
weak var adView : UIView ?
48
+ weak var containerView : UIView ?
48
49
49
50
private var adViewConstraints = [ NSLayoutConstraint] ( )
50
51
@@ -151,26 +152,27 @@ import WebKit
151
152
/// - Parameters:
152
153
/// - ad: inRead ad
153
154
/// - adRatio: ratio of the ad
154
- ///
155
+ /// - topOffset: topOffset of the View is 0 in most cases, useful if your website display a top bar and don't want the ad to overlap it
156
+ /// - bottomOffset: bottomOffset of the View is 0 in most cases, useful if your website display a bottom bar and don't want the ad to overlap it
155
157
/// - Note:
156
- /// sould be called from
158
+ /// should be called from
157
159
/// ```TeadsInReadAdPlacementDelegate.didReceiveAd(ad: TeadsInReadAd, adRatio: TeadsAdRatio)```
158
- @objc public func openSlot( ad: TeadsInReadAd , adRatio: TeadsAdRatio ) {
159
- openSlot ( adView: TeadsInReadAdView ( bind: ad) , adRatio: adRatio)
160
+ @objc public func openSlot( ad: TeadsInReadAd , adRatio: TeadsAdRatio , topOffset : CGFloat = 0.0 , bottomOffset : CGFloat = 0.0 ) {
161
+ openSlot ( adView: TeadsInReadAdView ( bind: ad) , adRatio: adRatio, topOffset : topOffset , bottomOffset : bottomOffset )
160
162
}
161
163
162
- @objc public func openSlot( adView: UIView , adRatio: TeadsAdRatio = . default) {
164
+ @objc public func openSlot( adView: UIView , adRatio: TeadsAdRatio = . default, topOffset : CGFloat = 0.0 , bottomOffset : CGFloat = 0.0 ) {
163
165
slotOpener = { [ self ] in
164
166
// update slot with the right ratio
165
167
self . updateSlot ( adRatio: adRatio)
166
168
167
169
// in case openSlot is called multiple times
168
170
self . adView? . removeFromSuperview ( )
169
171
172
+ adView. translatesAutoresizingMaskIntoConstraints = false
173
+ self . containerView = createContainerView ( topOffset: topOffset, bottomOffset: bottomOffset)
174
+ self . containerView? . addSubview ( adView)
170
175
self . adView = adView
171
- self . webView? . scrollView. addSubview ( adView)
172
- self . adView? . translatesAutoresizingMaskIntoConstraints = false
173
-
174
176
self . evaluateBootstrapInput ( JSBootstrapInput . showPlaceholder ( 0 ) ) { [ weak delegate] _, error in
175
177
if error != nil {
176
178
delegate? . webViewHelperOnError ( error: " openSlot failed " )
@@ -183,6 +185,22 @@ import WebKit
183
185
}
184
186
}
185
187
188
+ private func createContainerView( topOffset: CGFloat , bottomOffset: CGFloat ) -> UIView {
189
+ let container = UIView ( )
190
+ container. clipsToBounds = true
191
+ container. translatesAutoresizingMaskIntoConstraints = false
192
+ if let webView = webView {
193
+ webView. scrollView. addSubview ( container)
194
+ NSLayoutConstraint . activate ( [
195
+ container. topAnchor. constraint ( equalTo: webView. topAnchor, constant: topOffset) ,
196
+ container. bottomAnchor. constraint ( equalTo: webView. bottomAnchor, constant: - bottomOffset) ,
197
+ container. leadingAnchor. constraint ( equalTo: webView. leadingAnchor) ,
198
+ container. trailingAnchor. constraint ( equalTo: webView. trailingAnchor) ,
199
+ ] )
200
+ }
201
+ return container
202
+ }
203
+
186
204
/// Update the slot height with the given ad ratio
187
205
/// - Parameters:
188
206
/// - adRatio: ratio of the ad
0 commit comments