UIImageView userInteractionEnabled没有改变

时间:2012-08-08 16:05:46

标签: objective-c ios admob

我在Ad中创建了view App。我的Ad view中有一个“x”(退出)图片(我正在使用Google的adMob)。

正常加载Ad时一切正常。但是当出现错误并且Ad cant load我要显示自己的Ad时,我已经实现了以下方法:

- (void)adView:(GADBannerView *)bannerView
    didFailToReceiveAdWithError:(GADRequestError *)error{
    cloaseView.userInteractionEnabled = YES;
    shibbyAdImage.hidden = NO;
    NSLog(@"Failed to load Ad with error : %@", error);
}

由于某种原因userInteractionEnabled没有设置为是......

还有一些可能有用的代码:

这被称为加载Ad -

-(void)googleAd{

    // Create a view of the standard size at the bottom of the screen.
    // Available AdSize constants are explained in GADAdSize.h.
    bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeMediumRectangle];
    // Specify the ad's "unit identifier." This is your AdMob Publisher ID.
    bannerView_.adUnitID = MY_BANNER_UNIT_ID;

    //[bannerView_ setDelegate:self];    
    bannerView_.delegate = self;
    // Let the runtime know which UIViewController to restore after taking
    // the user wherever the ad goes and add it to the view hierarchy.
    bannerView_.rootViewController = self;
    [self.view addSubview:bannerView_];

    // Initiate a generic request to load it with an ad.
    [bannerView_ loadRequest:[GADRequest request]];
    NSLog(@"in googleAd");
}

放置Ad -

- (void)adViewDidReceiveAd:(GADBannerView *)bannerView {
    [UIView beginAnimations:@"BannerSlide" context:nil];
    bannerView.frame = CGRectMake(
                                      self.view.frame.size.width/2 -
                                      bannerView.frame.size.width/2,
                                      self.view.frame.size.height/2 -
                                      bannerView.frame.size.height/2,
                                      bannerView.frame.size.width,
                                      bannerView.frame.size.height);

    [UIView commitAnimations];
//    NSLog(@"in adViewDidReceiveAd");
//    NSLog(@"adpoint x: %g y: %g",adPoint.x, adPoint.y);
    cloaseView.userInteractionEnabled = YES;
}

1 个答案:

答案 0 :(得分:0)

首次设置usrInteraction时,请记录它:

cloaseView.userInteractionEnabled = YES;
NSLog(@"UserInteraction should now be on, its %d", cloaseView.userInteractionEnabled);

同样:

cloaseView.userInteractionEnabled = YES;

您可能需要沿着视图链(超级视图)向上走,以查看某个视图是否阻止了userInteraction:

您可以使用它来做到这一点(通过添加一个按钮或从计时器调用它时,一切都应该没问题:

@implementation UIView (Utilities)

+ (void)dumpSuperviews:(UIView *)v msg:(NSString *)msg
{
    NSMutableString *str = [NSMutableString stringWithCapacity:256];

    while(v) {
        [self appendView:v toStr:str];
        v = v.superview;
    }
    [str appendString:@"\n"];

    LTLog(@"%@:\n%@", msg, str);
}
+ (void)appendView:(UIView *)a toStr:(NSMutableString *)str
{
    [str appendFormat:@"  %@: frame=%@ bounds=%@ layerFrame=%@ tag=%d userInteraction=%d alpha=%f hidden=%d\n", 
        NSStringFromClass([a class]),
        NSStringFromCGRect(a.frame),
        NSStringFromCGRect(a.bounds),
        NSStringFromCGRect(a.layer.frame),
        a.tag, 
        a.userInteractionEnabled,
        a.alpha,
        a.isHidden
        ];
}

@end