뷰 기반 iPhone 프로젝트에 간단한 스 와이프 제스처 인식을 추가하고 싶습니다. 모든 방향 (오른쪽, 아래쪽, 왼쪽, 위쪽)의 제스처를 인식해야합니다.
UISwipeGestureRecognizer에 대한 문서에 명시되어 있습니다.
비트 OR 피연산자를 사용하여 여러 UISwipeGestureRecognizerDirection 상수를 지정하여 여러 방향을 지정할 수 있습니다. 기본 방향은 UISwipeGestureRecognizerDirectionRight입니다.
그러나 나를 위해 작동하지 않습니다. 네 방향이 모두 OR이면 왼쪽 및 오른쪽 스 와이프 만 인식됩니다.
- (void)viewDidLoad {
UISwipeGestureRecognizer *recognizer;
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionDown | UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionUp)];
[[self view] addGestureRecognizer:recognizer];
[recognizer release];
[super viewDidLoad];
}
-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {
NSLog(@"Swipe received.");
}
뷰에 4 명의 인식자를 추가 하여이 문제를 해결했지만 왜 문서에서 광고 된대로 작동하지 않는지 궁금합니다.
- (void)viewDidLoad {
UISwipeGestureRecognizer *recognizer;
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
[[self view] addGestureRecognizer:recognizer];
[recognizer release];
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];
[[self view] addGestureRecognizer:recognizer];
[recognizer release];
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionDown)];
[[self view] addGestureRecognizer:recognizer];
[recognizer release];
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
[[self view] addGestureRecognizer:recognizer];
[recognizer release];
[super viewDidLoad];
}
-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {
NSLog(@"Swipe received.");
}