2011-03-29 43 views
6

我创建一个通用的应用程序内的模板。iAd的 - 不能点击旗帜

此模板将需要支持可选的网络成瘾者,以及可选的所有方向。

我编写了一个解决方案却发现一个奇怪的错误。在某些情况下,我无法点击旗帜

然后我重新编码的另一个版本,收拾一切,烧毁了大部分代码,露出了最小的测试用例失败。

https://github.com/p-i-/iAdUniversalTemplate/commit/2c829d268a9452e1a054802e7ccb9cde5de17853

在这个新的代码中,只有3次:窗口,uberview(视图控制器的视图),以及广告横幅

所以,旗帜正常显示,一旦它已送达,自转工作正常... 我已经记录了每个框架和边界,并且一切都如它应该。

但它没有响应挖掘(当然,点击因为我在模拟器)

怎么可能是错的?我开始怀疑,在将XIB从项目中切割出来并从代码实现窗口和视图控制器时,我已经错过了某些东西,或者将某些东西重新连接起来。

多汁的代码块:

AppDelegate.m

- (BOOL) application: (UIApplication *) application 
didFinishLaunchingWithOptions: (NSDictionary *) launchOptions 
{ 
    NSLog(@"--> ___PROJECTNAME___AppDelegate:didFinishLaunchingWithOptions..."); 

    // FIXED: now entry in info.plist hides SB BEFORE launch 
    [[UIApplication sharedApplication] setStatusBarHidden: (SHOW_SB ? NO : YES)]; 

    CGRect appFrame = [UIScreen mainScreen].applicationFrame; 

    // windowRect must start at 0, 0 
    // if (SHOW_SB == YES), appFrame will be '{{0, 20}, {320, 460}}' 
    CGRect windowRect = CGRectMake(0, 0, appFrame.size.width, appFrame.size.height); 

    self.window = [[[UIWindow alloc] initWithFrame: windowRect] autorelease]; 

    self.viewController = [ [ [ ___PROJECTNAME___ViewController alloc ] init ] autorelease ]; 

    [self.window setRootViewController: viewController]; 

    // triggers loadView 
    [self.window makeKeyAndVisible]; 

    return YES; 
} 

iAdVC.m

- (void) loadView 
{  
    self.uberView = [[[UIView alloc] initWithFrame: [UIScreen mainScreen].applicationFrame] autorelease]; 
    self.uberView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
    self.uberView.autoresizesSubviews = YES; 
    self.uberView.clipsToBounds = YES; 

    //UIWindow * w = self.view.window; 
    //w.clipsToBounds = YES; 

    [self setView: uberView]; 

    showingBanner = NO; 
    adBannerView = nil; 
    if (IADS_ENABLED) 
    { 
     NSString * P = ADBannerContentSizeIdentifierPortrait; 
     NSString * L = ADBannerContentSizeIdentifierLandscape; 

     self.adBannerView = [[[ADBannerView alloc] initWithFrame:CGRectZero] autorelease]; 

     self.adBannerView.delegate = self; 
     self.adBannerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin; 
     self.adBannerView.requiredContentSizeIdentifiers = [NSSet setWithObjects: P, L, nil]; 
     self.adBannerView.currentContentSizeIdentifier = UIInterfaceOrientationIsPortrait(self.interfaceOrientation) ? P : L ; 

     [uberView addSubview: adBannerView]; 
    } 

    UIWindow * w = [[UIApplication sharedApplication] keyWindow]; 

    w.userInteractionEnabled = YES; 
    self.uberView.userInteractionEnabled = YES; 
    self.adBannerView.userInteractionEnabled = YES; 

    w.clipsToBounds = YES; 
    self.uberView.clipsToBounds = YES; 
    self.adBannerView.clipsToBounds = YES; 

    w.opaque = YES; 
    self.uberView.opaque = YES; 
    self.adBannerView.opaque = YES; 
} 

// - - - - - - - - - - - - - - - - - - - - - - - - - - 

#pragma mark Autorotate 

- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation 
{ 
    return YES; 
} 

// - - - - - - - - - - - - - - - - - - - - - - - - - - 

- (void) willRotateToInterfaceOrientation: (UIInterfaceOrientation) newOrientation 
           duration: (NSTimeInterval) duration 
{ 
    bool isLandscape = UIInterfaceOrientationIsLandscape(newOrientation); 
    self.adBannerView.currentContentSizeIdentifier = isLandscape ? ADBannerContentSizeIdentifierLandscape : ADBannerContentSizeIdentifierPortrait ; 
} 


#pragma mark Banner 

// - - - - - - - - - - - - - - - - - - - - - - - - - - 

- (void) bannerViewDidLoadAd: (ADBannerView *) banner 
{ 
    if (! showingBanner) 
    { 
     showingBanner = YES; 
     // ... (optionally animate in) 
    } 
} 


// - - - - - - - - - - - - - - - - - - - - - - - - - - 

- (void) bannerView: (ADBannerView *) banner 
didFailToReceiveAdWithError: (NSError *) error 
{ 
    NSLog(@"FAIL"); 

    if (showingBanner) 
    { 
     showingBanner = NO; 
     // ... (optionally animate out) 
    } 
} 

// - - - - - - - - - - - - - - - - - - - - - - - - - - 

-(BOOL) bannerViewActionShouldBegin: (ADBannerView *) banner 
       willLeaveApplication: (BOOL) willLeave 
{ 
    return YES; // doesnt get hit 
} 

// = = = = = = = = = = = = = = = = = = = = = = = = = = 
+0

您是否曾尝试将横幅添加到窗口的中间(将正确的CGRect提供到initWithFrame中),以确保它不会被其他可能在其他位置添加的其他不可见视图遮挡? – SVD 2011-03-29 16:13:09

回答

8

这是一个错误的母狗BLAT

我最后不得不用我的2个ITS热线的事件之一,并在其上失去了一个完整的工作周。

将uberView的backgroundColor属性设置为ANYTHING非零可修复问题。

这是一份得到由厦门国际银行魔术

做有一个名为nib2objc即转换到厦门国际银行代码工具的事情之一。如果我必须自己调试它,才能看到Apple的默认XIB中包含的内容,并查看我无法手动实现的内容,那么这将是下一步。

但是,这是UIKit中的错误。苹果公司的ITS代表告诉我要这样做,我已经这样做了。

+0

这工作!谢谢:-) – MrDatabase 2011-05-17 00:25:01

+0

谢谢!我从来没有猜到它与背景颜色有任何关系。刚花了几个小时试图弄清楚。 – briangraf 2011-07-24 03:35:08

+0

我从来没有想过,设置横幅的背景颜色清除会阻止它的工作,谢谢! – 2012-04-10 09:46:39

2

我有同样的问题,但使用[UIColor clearColor]作为superview的背景并没有帮助。 (这是在iOS 4.3.3上)

所有superviews需要有一个不透明颜色集。

0

我确认加入

self.window.backgroundColor = [UIColor whiteColor]; 

didFinishLaunchingWithOptions功能完美的作品。