1
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을 흔들고 싶습니다. 이 경우 흔들림은 카운트되지 않습니다. 마치 화면에 닿지 않는 것처럼. 나는 화면에서 한 손을 뗄 때 두 "닿기"가 제거된다고 가정합니다.
무엇이 문제이며 어떻게 해결할 수 있습니까?
감사합니다.