在我當前的ios項目中,我將屏幕的一側分配給一個對象,屏幕的另一側分配給另一個對象,並且我做到了這樣,如果您將手指劃過指定對象上屏幕的一側會移動。但是,我想讓它能夠在不同的運動中同時移動兩個物體,但我無法弄清楚如何去做。以下是我目前的代碼。同時移動2個對象
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
if (location.x <= 270) {
[Person setCenter:CGPointMake(location.x, Person.center.y)];
}
else {
[Person1 setCenter:CGPointMake(location.x, Person1.center.y)];
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
if (location.x <= 270) {
[Person setCenter:CGPointMake(location.x, Person.center.y)];
}
else {
[Person1 setCenter:CGPointMake(location.x, Person1.center.y)];
}
}
我面對同樣的問題與此代碼,因爲我用我的原始代碼。我試圖重寫我的方法來編寫我的機制,但我不能完全弄清楚如何讓對象同時移動,謝謝您的輸入,但是 – user3795419 2014-09-30 00:18:02
@ user3795419所以當您開始進行多點觸摸時發生了什麼?你能形容嗎?代碼應該工作......謝謝 – DaTa 2014-09-30 01:23:46
我只能一次移動其中一個對象。當我嘗試通過在指定區域上滑動手指同時移動兩個對象時,只有其中一個移動了 – user3795419 2014-09-30 03:31:53