Мультитач вопрос
-
06-07-2019 - |
Вопрос
Я хочу определить, к какой части экрана прикасаются, когда пользователь встряхивает iPhone.
Я делаю это следующим образом:
-(void) accelerometer: (UIAccelerometer*)accelerometer didAccelerate: (UIAcceleration*)acceleration
{
float shakeStrength = sqrt( acceleration.x * acceleration.x + acceleration.y * acceleration.y + acceleration.z * acceleration.z );
if (shakeStrength >= 1.5f)
{
if (isLeftHandTouches && isRightHandTouches)
{
DebugLog(@"both hands shake");
} else if (isLeftHandTouches)
{
DebugLog(@"left hand shake");
} else if (isRightHandTouches)
{
DebugLog(@"right hand shake");
}
}
}
-(void) touchesBegan: (NSSet *)touches withEvent: (UIEvent *)event
{
NSSet *allTouches = [event allTouches];
for (int i = 0; i < [allTouches count]; i++)
{
if ([ [ [allTouches allObjects] objectAtIndex: i] locationInView: [self view] ].x <= 240.0f)
{
isLeftHandTouches = YES;
} else
{
isRightHandTouches = YES;
}
}
}
-(void) touchesEnded: (NSSet *)touches withEvent: (UIEvent *)event
{
NSSet *allTouches = [event allTouches];
for (int i = 0; i < [allTouches count]; i++)
{
if ([ [ [allTouches allObjects] objectAtIndex: i] locationInView: [self view] ].x <= 240.0f)
{
isLeftHandTouches = NO;
} else
{
isRightHandTouches = NO;
}
}
}
Все работает нормально, если пользователь убирает обе руки перед следующим встряхиванием, но все становится не так, если я держу обе руки на экране и убираю одну из них.
то естьЯ трясу обеими руками экран, а потом хочу трясти iPhone только одной рукой.В этом случае тряска не засчитывается - как будто касаний по экрану нет.Я предполагаю, что когда я убираю одну руку с экрана, убираются оба "касания".
В чем проблема и как ее исправить?
Спасибо.
Решение
Зачем ты перечисляешь -allTouches
?Просто перечислите touches
набор, который передается.То же самое касается обоих методов.
Не связан с StackOverflow