스 와이프 오른쪽 제스처와 길게 누르는 제스처를 인식하는 두 개의 제스처 인식기가 있습니다. 위임 메서드 gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
을 사용하려고 시도했지만 스 와이프 및 길게 누르는 제스처를 수행 할 때마다 메서드가 한 번이 아닌 여러 번 호출되었습니다. 제스처 인식기 설정, 위임 메서드 호출 및 일단 수행 된 제스처 처리에 다음 코드를 사용합니다.스 와이프 및 고정 제스처 인식기를 구현하는 방법은 무엇입니까?
//Setting up the swipe gesture recognizer
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeRight:)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
swipeRight.delegate = self;
[self addGestureRecognizer:swipeRight];
//Setting up the long press gesture recognizer
UILongPressGestureRecognizer *rightLongPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeRight:)];
rightLongPressRecognizer.delegate = self;
rightLongPressRecognizer.tag = PRESS_RIGHT_TAG;
[rightLongPressRecognizer setMinimumPressDuration:0.5];
[self addGestureRecognizer:rightLongPressRecognizer];
//Delegate method
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
//Method that the gestures call
-(void)handleSwipeRight: (UIGestureRecognizer *)recognizer {
self.player.direction = RIGHT;
[self resetSpriteView];
[self.playerSprite startAnimating];
float playerSpriteX = self.playerSprite.center.x;
float playerSpriteY = self.playerSprite.center.y;
self.toPoint = CGPointMake(playerSpriteX + TILE_WIDTH, playerSpriteY);
if(!([self checkIfPlayerHasReachedEnd])) {
self.fromPoint = CGPointMake(playerSpriteX, playerSpriteY);
CABasicAnimation *moveAnimation = [CABasicAnimation animation];
moveAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(playerSpriteX + TILE_WIDTH, playerSpriteY)];
[moveAnimation setDelegate:self];
[moveAnimation setFillMode:kCAFillModeForwards];
[moveAnimation setRemovedOnCompletion:NO];
[moveAnimation setDuration:MOVE_ANIMATION_DURATION];
[self.playerSprite.layer addAnimation:moveAnimation forKey:@"position"];
}
}
강타를 구현하고 제스처 인식기을 유지하는 더 좋은 방법이 있나요?
좋은 질문, +1을. –
같은 방법으로 두 제스처를 모두 처리하는 이유는 무엇입니까? 그것은 당신이 그 일을 처리하면 더 복잡 해지는 것이 정상입니다. – Peres
@ JackyBoy - 제스처 인식기를 작동시키는 방법을 설정해야한다고 생각했기 때문에 무엇을해야할지 모르겠습니다. 그것을 할 수있는 더 좋은 방법이 있습니까? – pasawaya