Detect and ignore touches on iAd banners

别来无恙 提交于 2019-12-24 12:33:50

问题


I have a Sprite Kit game that first displays a menu screen. The game starts when you tap anywhere on the screen. I am displaying iAd's. The problem I have is when a user taps the iAd banner to view the add, GameScene is responding to the tap and starting the game. Ideally I want to detect that the touch was on the iAd banner and not start the game in this case.

GameScene.m

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{

    // I dont want to start game if the touch was on the iAd Banner
    NSLog(@"Touch detected - Start the game....");

    [self startGame];
}

回答1:


use a UITapGestureRecognizer instead. Check if recognizer.view != adBanner




回答2:


Have you tried making the SKView smaller in the GameViewController?

Try making

yourScene.size = CGSize(skView.bounds.size.width, skView.bounds.size.height-heightOfiAdBanner)

Change heightOfiAdBanner with the actual height of the iAd banner. And then position the scene wherever you must to see it properly (depending on where you display the banner). Remember to use

yourScene.size = skView.bounds.size

when you remove the banner. With this solution you do not have to use any gesture recognizer.




回答3:


One option is to check the location.

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{
    // get location
    UITouch *touch = [[event allTouches] anyObject];
    CGPoint location = [touch locationInView:touch.view];

    // check position
    if (CGRectContainsPoint(self.adBanner.frame, location) {
        // start game

    }
}


来源:https://stackoverflow.com/questions/33246378/detect-and-ignore-touches-on-iad-banners

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!