2014-02-19 101 views
0

我正在創建一個遊戲,並且當前如果您觸摸屏幕的左半邊,則槍會順時針旋轉,如果觸摸屏幕的右半邊,則會進行拍攝。iOS一次檢測到多個觸摸

我想創建一個動作,以便如果我觸摸屏幕的左半部分,它將順時針旋轉,如果您觸摸右半部分則逆時針旋轉。這很容易。

如果我在同一時間觸摸左右兩側,我想要拍攝。這怎麼可能同時檢測2個觸摸。

這是因爲,如果觸摸的右半

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

    if (touchPoint.x < self.size.width/2.0) { 
     isTouching = true; 
    } 
    else 
     [self setupBullet]; 
} 
當觸摸左半邊和拍攝順時針旋轉代碼
+0

[觸及allObjects]? –

回答

1

你要麼需要設置兩個不同的對象,在他們各自的側面觸摸事件收聽,或您可以使用event.allTouches對象並獲取當前所有觸摸對象的完整陣列,並按照您的意願處理該陣列。

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    //either: 
    if(touch in left side) 
    { 
     //Left side touch down, create object 
    } 
    else 
    { 
     //Right side touch down, create object 
    } 

    //Or: 
    NSArray *arrayOfAllTouches = event.allTouches; 
    //Now loop through that array and see what is going on on screen 
} 

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 
    //either: 
    if(touch in left side) 
    { 
     //Left side release, release object 
    } 
    else 
    { 
     //Right side release, release object 
    } 

    //Or: 
    NSArray *arrayOfAllTouches = event.allTouches; 
    //Now loop through that array and see what is going on on screen 
}