【问题标题】:When I tap AdView, CCMenuItem respond当我点击 AdView 时,CCMenuItem 响应
【发布时间】:2013-03-06 13:44:02
【问题描述】:

我正在使用 kobold2d v2.1.0 并根据 Google 的说明将 AdMob Mediation SDK 添加到我的项目中。

我创建了AdViewController 并将其视图添加到rootViewController.view

AdViewController.m:

-(void)viewDidLoad
{
    [super viewDidLoad];

    // Initialize the banner at the bottom of the screen.
    CGPoint origin = CGPointMake(0.0,
                     self.view.frame.size.height -
                     CGSizeFromGADAdSize(kGADAdSizeBanner).height);

    // Use predefined GADAdSize constants to define the GADBannerView.
    self.adBanner = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner
                                               origin:origin];

    // before compiling.
    self.adBanner.adUnitID = AD_UNIT_ID;
    self.adBanner.delegate = self;
    [self.adBanner setRootViewController:self];
    [self.view addSubview:self.adBanner];
    self.adBanner.center =
    CGPointMake(self.view.center.x, self.adBanner.center.y);
    [self.adBanner loadRequest:[self createRequest]];
}

AppDelegete.m

-(void) initializationComplete
{
    adViewController = [[AdViewController alloc] init];
    [self.rootViewController.view addSubview:adViewController.view];
}

-(id) alternateView
{
    // we want to be a dummy view the self.view to which we add the glView plus all other UIKit views
    KKAppDelegate* appDelegate = (KKAppDelegate*)[UIApplication sharedApplication].delegate;

    // add a dummy UIView to the view controller, which in turn will have the glView and later other UIKit views added to it
    CGRect bounds = [appDelegate.window bounds];
    UIView* dummyView = [[UIView alloc] initWithFrame:bounds];

    [dummyView addSubview:[CCDirector sharedDirector].view];

    return dummyView;
}

当我在显示广告之前点击广告区域时,远程CCMenuItem被按下,就像我点击CCMenuItem一样。

请看这个

我认为这与this question有关,但我不知道如何解决。

请告诉我如何防止CCMenuItem响应远程位置的点击。

对不起,我英语不好。

【问题讨论】:

    标签: cocos2d-iphone kobold2d ccmenuitem ccmenu


    【解决方案1】:

    我通过更改 CCMenu.m 中的 -(CCMenuItem *) itemForTouch: (UITouch *) touch 方法解决了这个问题。

    -(CCMenuItem *) itemForTouch: (UITouch *) touch
    {
        //CGPoint touchLocation = [touch locationInView: [touch view]];
        /*changed*/ CGPoint touchLocation = [touch locationInView: [CCDirector sharedDirector].view];
        touchLocation = [[CCDirector sharedDirector] convertToGL: touchLocation];
    
        .......
    
    }
    

    改变[touch view]之前是AdView,所以CCMenu得到了错误的坐标。

    我指的是this question

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-04
      • 1970-01-01
      • 2019-11-18
      • 2020-08-19
      • 1970-01-01
      • 2012-06-12
      • 1970-01-01
      • 2021-02-10
      相关资源
      最近更新 更多