UIImageView userInteractionEnabled not changing



我在App中创建了一个Ad view。我的Ad view中有一个"x"(退出)图片(我使用的是谷歌的adMob)。

Ad正常加载时,一切都很好。但是当出现错误并且Ad无法加载时,我想显示自己的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;
}

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

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

与:

cloaseView.userInteractionEnabled = YES;

您可能需要沿着视图链向上(超级视图向上)浏览,以查看某些视图是否阻止了用户交互:

您可以使用它来执行此操作(通过添加按钮或在一切正常时从计时器调用它:

@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=%dn", 
        NSStringFromClass([a class]),
        NSStringFromCGRect(a.frame),
        NSStringFromCGRect(a.bounds),
        NSStringFromCGRect(a.layer.frame),
        a.tag, 
        a.userInteractionEnabled,
        a.alpha,
        a.isHidden
        ];
}
@end

最新更新