2016-07-27 6 views
1

나는 한 번에 두 인물로 움직이는 게임을 만들고있다. 각각 하나는 화면의 절반을 가지고 있으며 안으로 들어가서 움직입니다. 불행히도 나는 한 번에 두 엄지 손가락으로 쓸어 넘기면 아무 일도 일어나지 않는다는 것을 알았습니다. 내 인식기 중 하나도 실행되지 않습니다.시뮬레이트적인 독립적 인 제스처

어쩌면 편도가 있습니다. GameViewController 상단에 또 다른 두 가지 뷰를 만들고 별도의 제스처를 추가했습니다. 그러나 나는 게임을 통해 그들에게 행동을하기를 거부합니다.

GameScene에서 GameScController에서 선언 한 스 와이프를 인식하고 액션을 추가 할 수 있습니까?

나는 터치에 따라 이미 인식기를 만들려고 노력했지만 두 손가락이 한꺼번에 풀려 나올 때마다 지저분 해지고 대개 두 번 반응하는 것을 잊어 버렸다.

-(void)setUpGestActions{ 
    _swipeGestureLeft = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeLeft:)]; 
    [self.swipeGestureLeft setDirection:UISwipeGestureRecognizerDirectionLeft]; 
    self.swipeGestureLeft.cancelsTouchesInView = NO; 
    self.swipeGestureLeft.delegate = self; 
    [self.view addGestureRecognizer: self.swipeGestureLeft]; 

    _swipeGestureRight = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeRight:)]; 
    [self.swipeGestureRight setDirection:UISwipeGestureRecognizerDirectionRight]; 
    self.swipeGestureRight.cancelsTouchesInView = NO; 
    self.swipeGestureRight.delegate = self; 
    [self.view addGestureRecognizer: self.swipeGestureRight]; 

    _swipeGestureUp = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeUp:)]; 
    [self.swipeGestureUp setDirection:UISwipeGestureRecognizerDirectionUp]; 
    self.swipeGestureUp.cancelsTouchesInView = NO; 
    self.swipeGestureUp.delegate = self; 
    [self.view addGestureRecognizer: self.swipeGestureUp]; 

    _swipeGestureDown = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeDown:)]; 
    [self.swipeGestureDown setDirection:UISwipeGestureRecognizerDirectionDown]; 
    self.swipeGestureDown.cancelsTouchesInView = NO; 
    self.swipeGestureDown.delegate = self; 
    [self.view addGestureRecognizer: self.swipeGestureDown]; 

    _moveLeft = [SKAction moveByX:-self.frame.size.width/6 y:0 duration:self.velocity]; 
    _moveRight = [SKAction moveByX:self.frame.size.width/6 y:0 duration:self.velocity]; 
    _moveUp = [SKAction moveByX:0 y:self.frame.size.width/6 duration:self.velocity]; 
    _moveDown = [SKAction moveByX:0 y:-self.frame.size.width/6 duration:self.velocity]; 

    _downMovement = [SKAction moveByX:0 y:-1 duration:self.downMovementVelocity]; 
} 

-(void)swipeLeft:(UISwipeGestureRecognizer*) recognizer{ 
    _sideDisting = [recognizer locationInView:self.view]; 
    if(self.sideDisting.x <= self.frame.size.width/2){ 
     [_boy runAction:self.moveLeft]; 
    } 
    else{ 
     [_girl runAction:self.moveLeft]; 

    } 
} 

-(void)swipeRight:(UISwipeGestureRecognizer*) recognizer{ 
    _sideDisting = [recognizer locationInView:self.view]; 
    if(self.sideDisting.x <= self.frame.size.width/2){ 
     [_boy runAction:self.moveRight]; 
    } 
    else{ 
     [_girl runAction:self.moveRight]; 
    } 
} 

-(void)swipeUp:(UISwipeGestureRecognizer*) recognizer{ 
    _sideDisting = [recognizer locationInView:self.view]; 
    if(self.sideDisting.x <= self.frame.size.width/2){ 
     [_boy runAction:self.moveUp]; 
    } 
    else{ 
     [_girl runAction:self.moveUp]; 
    } 
} 

-(void)swipeDown:(UISwipeGestureRecognizer*) recognizer{ 
    _sideDisting = [recognizer locationInView:self.view]; 
    if(self.sideDisting.x <= self.frame.size.width/2){ 
     [_boy runAction:self.moveDown]; 
    } 
    else{ 
     [_girl runAction:self.moveDown]; 

    } 
} 

답변

0

간단한 해결책은 두 사소한보기로 화면을 분할하여 각각 별도의 제스처 인식기를 부착하는 것이다.

1

여러 제스처를 동시에 인식하려면 각 제스처 인식기에 대리인을 설정하십시오. 대리자는 각 제스처에 대해 동일한 개체가 될 수 있습니다. 대리자에서

,이를 구현 :

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer 
    shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { 
    return YES; 
} 
+0

나는 이미이 작업을 수행했지만 아무런 결과가 없습니다. interface 및 bool의 델리게이트를 YES로 설정하면 self.swipeGestureDown.delegate = self; alloc 코드의 각 블록에있는 행. 더블 슬쩍이나 뭔가 다른 인식기와 혼동을 일으킬 수 있습니다. (나는 내 ​​코드에서 그런 것을 선언하지 않았다) –

0

난 당신이 예에서 볼 수 있다고 생각합니다. 도움이 될만한 정보가 있습니다.

UIScreenEdgePanGestureRecognizer *myScreenEdgePanGestureRecognizer; 
... 
myScreenEdgePanGestureRecognizer = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(handleScreenEdgePan:)]; 
myScreenEdgePanGestureRecognizer.delegate = self; 
// Configure the gesture recognizer and attach it to the view. 
... 
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { 
    BOOL result = NO; 
    if ((gestureRecognizer == myScreenEdgePanGestureRecognizer) && [[otherGestureRecognizer view] isDescendantOfView:[gestureRecognizer view]]) { 
     result = YES; 
    } 
    return result; 
} 

자세한 내용은이 링크를 참조하십시오.

https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/GestureRecognizer_basics/GestureRecognizer_basics.html