• <bdo id='b4aFZ'></bdo><ul id='b4aFZ'></ul>
      <legend id='b4aFZ'><style id='b4aFZ'><dir id='b4aFZ'><q id='b4aFZ'></q></dir></style></legend>

        <small id='b4aFZ'></small><noframes id='b4aFZ'>

        <tfoot id='b4aFZ'></tfoot>
        <i id='b4aFZ'><tr id='b4aFZ'><dt id='b4aFZ'><q id='b4aFZ'><span id='b4aFZ'><b id='b4aFZ'><form id='b4aFZ'><ins id='b4aFZ'></ins><ul id='b4aFZ'></ul><sub id='b4aFZ'></sub></form><legend id='b4aFZ'></legend><bdo id='b4aFZ'><pre id='b4aFZ'><center id='b4aFZ'></center></pre></bdo></b><th id='b4aFZ'></th></span></q></dt></tr></i><div id='b4aFZ'><tfoot id='b4aFZ'></tfoot><dl id='b4aFZ'><fieldset id='b4aFZ'></fieldset></dl></div>

        无法隐藏 iAd 横幅并在其位置显示 UIWebView

        时间:2023-11-09

        <small id='9cw4X'></small><noframes id='9cw4X'>

        <tfoot id='9cw4X'></tfoot>
          1. <i id='9cw4X'><tr id='9cw4X'><dt id='9cw4X'><q id='9cw4X'><span id='9cw4X'><b id='9cw4X'><form id='9cw4X'><ins id='9cw4X'></ins><ul id='9cw4X'></ul><sub id='9cw4X'></sub></form><legend id='9cw4X'></legend><bdo id='9cw4X'><pre id='9cw4X'><center id='9cw4X'></center></pre></bdo></b><th id='9cw4X'></th></span></q></dt></tr></i><div id='9cw4X'><tfoot id='9cw4X'></tfoot><dl id='9cw4X'><fieldset id='9cw4X'></fieldset></dl></div>
            <legend id='9cw4X'><style id='9cw4X'><dir id='9cw4X'><q id='9cw4X'></q></dir></style></legend>
              • <bdo id='9cw4X'></bdo><ul id='9cw4X'></ul>

                    <tbody id='9cw4X'></tbody>

                  本文介绍了无法隐藏 iAd 横幅并在其位置显示 UIWebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  当没有要显示的 iAd 横幅时,我们希望显示指向特定 URL 的相同尺寸的 UIWebView.

                  When there is no iAd banner to display, we would like to display a UIWebView of the same dimensions pointed to a specific URL.

                  但是,隐藏 iAd 横幅并显示 UIWebView 不起作用.我们在 bannerViewDidLoadAddidFailToReceiveAdWithError 中嵌入了显示/隐藏代码.当没有 iAd 库存而不是我们的 UIWebView 时,出现的只是白色的空白矩形.

                  However, hiding the iAd banner and showing the UIWebView doesn't work. We embed the show/hide code inside bannerViewDidLoadAd and didFailToReceiveAdWithError. All that appears is the white, blank rectangle when there is no iAd inventory instead of our UIWebView.

                  如果用户单击 UIWebView 内的链接,我们希望该链接在 Safari 中打开.我们是否需要向 UIWebView 添加委托?

                  If a user clicks on a link inside the UIWebView, we would like the link to open in Safari. Do we need to add a delegate to the UIWebView?

                  代码:

                  //
                  //  SAiOSAdPlugin.m
                  //  Ad Plugin for PhoneGap
                  //
                  //  Created by shazron on 10-07-12.
                  //  Copyright 2010 Shazron Abdullah. All rights reserved.
                  //  Cordova v1.5.0 Support added 2012 @RandyMcMillan
                  //
                  
                  #import "SAiOSAdPlugin.h"
                  
                  //#ifdef CORDOVA_FRAMEWORK
                  #import <Cordova/CDVDebug.h>
                  //#else
                  //#import "CDVDebug.h"
                  //#endif
                  
                  @interface SAiOSAdPlugin(PrivateMethods)
                  
                  - (void) __prepare:(BOOL)atBottom;
                  - (void) __showAd:(BOOL)show;
                  
                  @end
                  
                  
                  @implementation SAiOSAdPlugin
                  
                  @synthesize adView;
                  @synthesize bannerIsVisible, bannerIsInitialized, bannerIsAtBottom, isLandscape;
                  
                  #pragma mark -
                  #pragma mark Public Methods
                  
                  - (void) resizeViews
                  {
                      Class adBannerViewClass = NSClassFromString(@"ADBannerView");
                      if (adBannerViewClass && self.adView)
                      {
                          CGRect webViewFrame = [super webView].frame;
                          CGRect superViewFrame = [[super webView] superview].frame;
                          CGRect adViewFrame = self.adView.frame;
                  
                          BOOL adIsShowing = [[[super webView] superview].subviews containsObject:self.adView];
                          if (adIsShowing) 
                          {
                              if (self.bannerIsAtBottom) {
                                  webViewFrame.origin.y = 0;
                                  CGRect adViewFrame = self.adView.frame;
                                  CGRect superViewFrame = [[super webView] superview].frame;
                                  adViewFrame.origin.y = (self.isLandscape ? superViewFrame.size.width : superViewFrame.size.height) - adViewFrame.size.height;
                                  self.adView.frame = adViewFrame;
                              } else {
                                  webViewFrame.origin.y = adViewFrame.size.height;
                              }
                  
                              webViewFrame.size.height = self.isLandscape? (superViewFrame.size.width - adViewFrame.size.height) : (superViewFrame.size.height - adViewFrame.size.height);
                          } 
                          else 
                          {
                              webViewFrame.size = self.isLandscape? CGSizeMake(superViewFrame.size.height, superViewFrame.size.width) : superViewFrame.size;
                              webViewFrame.origin = CGPointZero;
                          }
                  
                          [UIView beginAnimations:@"blah" context:NULL];
                          [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
                  
                          [super webView].frame = webViewFrame;
                  
                          [UIView commitAnimations];
                      }
                  }
                  
                  - (void) orientationChanged:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
                  {
                      NSInteger orientation = [[arguments objectAtIndex:0] integerValue];
                  
                      switch (orientation) {
                          // landscape
                          case 90:
                          case -90:
                              self.isLandscape = YES;
                              break;
                          // portrait
                          case 0:
                          case 180:
                              self.isLandscape = NO;
                              break;
                          default:
                              break;
                      }
                  
                      Class adBannerViewClass = NSClassFromString(@"ADBannerView");
                      if (adBannerViewClass && self.adView)
                      {
                          self.adView.currentContentSizeIdentifier = self.isLandscape ? ADBannerContentSizeIdentifierLandscape : ADBannerContentSizeIdentifierPortrait;
                          [self resizeViews];
                      }
                  }
                  
                  - (void) prepare:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
                  {
                      NSUInteger argc = [arguments count];
                      if (argc > 1) {
                          return;
                      }
                  
                      NSString* atBottomValue = [arguments objectAtIndex:0];
                      [self __prepare:[atBottomValue boolValue]];
                  }
                  
                  - (void) showAd:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
                  {
                      NSUInteger argc = [arguments count];
                      if (argc > 1) {
                          return;
                      }
                  
                      NSString* showValue = [arguments objectAtIndex:0];
                      [self __showAd:[showValue boolValue]];
                  }
                  
                  #pragma mark -
                  #pragma mark Private Methods
                  
                  - (void) __prepare:(BOOL)atBottom
                  {
                      NSLog(@"SAiOSAdPlugin Prepare Ad At Bottom: %d", atBottom);
                  
                      Class adBannerViewClass = NSClassFromString(@"ADBannerView");
                      if (adBannerViewClass && !self.adView)
                      {
                          self.adView = [[ADBannerView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
                          // we are still using these constants even though they are deprecated - if it is changed, iOS 4 devices < 4.3 will crash.
                          // will need to do a run-time iOS version check 
                          self.adView.requiredContentSizeIdentifiers = [NSSet setWithObjects: ADBannerContentSizeIdentifierPortrait, ADBannerContentSizeIdentifierLandscape, nil];        
                  
                          self.adView.delegate = self;
                  
                          NSString* contentSizeId = (self.isLandscape ? ADBannerContentSizeIdentifierLandscape : ADBannerContentSizeIdentifierPortrait);
                  
                          self.adView.currentContentSizeIdentifier = contentSizeId;
                  
                          if (atBottom) {
                              self.bannerIsAtBottom = YES;
                          }
                  
                          self.bannerIsVisible = NO;
                          self.bannerIsInitialized = YES;
                  
                          self.houseAdView = [[UIWebView alloc] initWithFrame: CGRectMake(0.0, 0.0, 1.0, 1.0)];
                          self.houseAdView.frame = self.adView.frame;
                          NSURLRequest *request = [[NSURLRequest alloc] initWithURL: [NSURL URLWithString: @"http://www.panabee.com"]];
                          [self.houseAdView loadRequest: request];
                  
                      }
                  }
                  
                  - (void) __showAd:(BOOL)show
                  {
                      NSLog(@"SAiOSAdPlugin Show Ad: %d", show);
                  
                      if (!self.bannerIsInitialized){
                          [self __prepare:NO];
                      }
                  
                      if (!(NSClassFromString(@"ADBannerView") && self.adView)) { // ad classes not available
                          return;
                      }
                  
                      if (show == self.bannerIsVisible) { // same state, nothing to do
                          return;
                      }
                  
                      if (show)
                      {
                          [UIView beginAnimations:@"blah" context:NULL];
                          [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
                  
                          [[[super webView] superview] addSubview:self.adView];
                          [[[super webView] superview] bringSubviewToFront:self.houseAdView];
                          [[[super webView] superview] bringSubviewToFront:self.adView];
                          [self resizeViews];
                  
                          [UIView commitAnimations];
                  
                          self.bannerIsVisible = YES;
                      }
                      else 
                      {
                          [UIView beginAnimations:@"blah" context:NULL];
                          [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
                  
                          [self.adView removeFromSuperview];
                          [self resizeViews];
                  
                          [UIView commitAnimations];
                  
                          self.bannerIsVisible = NO;
                      }
                  
                  }
                  
                  #pragma mark -
                  #pragma ADBannerViewDelegate
                  
                  - (void)bannerViewDidLoadAd:(ADBannerView *)banner
                  {
                      Class adBannerViewClass = NSClassFromString(@"ADBannerView");
                      if (adBannerViewClass)
                      {
                          NSString* jsString =
                          @"(function(){"
                          "var e = document.createEvent('Events');"
                          "e.initEvent('iAdBannerViewDidLoadAdEvent');"
                          "document.dispatchEvent(e);"
                          "})();";
                  
                          [banner setHidden:YES];
                          [self.houseAdView setHidden:NO];
                  
                          [super writeJavascript:[NSString stringWithFormat:jsString]];
                      }
                  }
                  
                  - (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError*)error
                  {
                      Class adBannerViewClass = NSClassFromString(@"ADBannerView");
                      if (adBannerViewClass)
                      {
                          NSString* jsString = 
                          @"(function(){"
                          "var e = document.createEvent('Events');"
                          "e.initEvent('iAdBannerViewDidFailToReceiveAdWithErrorEvent');"
                          "e.error = '%@';"
                          "document.dispatchEvent(e);"
                          "})();";
                  
                          [banner setHidden:YES];
                          [self.houseAdView setHidden:NO];
                  
                          [super writeJavascript:[NSString stringWithFormat:jsString, [error description]]];
                      }
                  }
                  
                  @end
                  

                  推荐答案

                  又是我 :)

                  从你的 __prepare 方法

                  self.houseAdView = [[UIWebView alloc] initWithFrame: CGRectMake(0.0, 0.0, 1.0, 1.0)];
                  self.houseAdView.frame = self.adView.frame;
                  NSURLRequest *request = [[NSURLRequest alloc] initWithURL: [NSURL URLWithString: @"http://www.panabee.com"]];
                  [self.houseAdView loadRequest: request];
                  

                  那太好了.但它不起作用 - 你缺少 一行 代码 - 一个关键的、重要的行,它让每个开发人员都花些时间.

                  That's great. But it doesn't work - you are missing one line of code - a critical, vital line that gets every developer some time or another.

                  [self addSubview:self.houseAdView];
                  

                  我做了一些假设,比如 self 是一个 UIView.发货前测试.

                  I'm making a few assumptions, like that self is a UIView. Test before shipping.

                  所以,你的 __prepare 方法的那部分应该是这样的:

                  So, that part of your __prepare method should look like this:

                  self.houseAdView = [[UIWebView alloc] initWithFrame: CGRectMake(0.0, 0.0, 1.0, 1.0)];
                  self.houseAdView.frame = self.adView.frame;
                  NSURLRequest *request = [[NSURLRequest alloc] initWithURL: [NSURL URLWithString: @"http://www.panabee.com"]];
                  [self.houseAdView loadRequest: request];
                  [self addSubview:self.houseAdView];
                  

                  这篇关于无法隐藏 iAd 横幅并在其位置显示 UIWebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:知道何时在 UIWebView 中加载了 AJAX 下一篇:NSCachedURLResponse 返回对象,但 UIWebView 不解释内容

                  相关文章

                • <legend id='VXKTn'><style id='VXKTn'><dir id='VXKTn'><q id='VXKTn'></q></dir></style></legend>
                  <i id='VXKTn'><tr id='VXKTn'><dt id='VXKTn'><q id='VXKTn'><span id='VXKTn'><b id='VXKTn'><form id='VXKTn'><ins id='VXKTn'></ins><ul id='VXKTn'></ul><sub id='VXKTn'></sub></form><legend id='VXKTn'></legend><bdo id='VXKTn'><pre id='VXKTn'><center id='VXKTn'></center></pre></bdo></b><th id='VXKTn'></th></span></q></dt></tr></i><div id='VXKTn'><tfoot id='VXKTn'></tfoot><dl id='VXKTn'><fieldset id='VXKTn'></fieldset></dl></div>

                • <small id='VXKTn'></small><noframes id='VXKTn'>

                  <tfoot id='VXKTn'></tfoot>

                    <bdo id='VXKTn'></bdo><ul id='VXKTn'></ul>