问题
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