检测屏幕左/右部分的触摸

时间:2013-05-15 14:42:24

标签: ios objective-c cocoa-touch uitouch

我想创建一个游戏,但我需要检测屏幕左侧或右侧是否触摸屏幕(横向)。我怎么能这样做?

1 个答案:

答案 0 :(得分: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!");
}