-1

我想创建一个游戏,但我需要检测屏幕是在屏幕的左侧还是右侧(横向)被触摸。我怎样才能做到这一点?

4

1 回答 1

3

我建议在发布问题之前先查看一个好的 iOS 教程,例如iOS Stanford。然而,与此同时,这样的事情会奏效:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *myTouch = [touches anyObject];

    CGPoint aPoint = [myTouch locationInView:self.view];

    if(aPoint.x < 160) { //Left
        NSLog(@"Tapping on the left side of the screen is for communists!");
    else // Right
        NSLog(@"User tapped on the right side! Ohh Yeah!");
}
于 2013-05-15T15:11:32.437 回答