我想创建一个游戏,但我需要检测屏幕左侧或右侧是否触摸屏幕(横向)。我怎么能这样做?
答案 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!");
}