UISWipeGestureRecognizer @Selector가 UIPAngeStureRecognizer 설정으로 인해 호출되지 않습니다.

StackOverflow https://stackoverflow.com//questions/22055625

문제

내 iOS 앱에서는 다음과 같은 설정이 있습니다.

- (void)setupGestures
{
   UIPanGestureRecognizer* panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGesture:)];                                                           
   [self.view addGestureRecognizer:panRecognizer];

   UISwipeGestureRecognizer* swipeUpRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];

   [swipeUpRecognizer setDirection:UISwipeGestureRecognizerDirectionUp];
   [self.view addGestureRecognizer:swipeUpRecognizer];
}

// then I have following implementation of selectors

// this method supposed to give me the length of the swipe

- (void)panGesture:(UIPanGestureRecognizer *)sender 
{
   if (sender.state == UIGestureRecognizerStateBegan)
   {
      startLocation = [sender locationInView:self.view];
   }
   else if (sender.state == UIGestureRecognizerStateEnded)
   {
      CGPoint stopLocation = [sender locationInView:self.view];
      CGFloat dx = stopLocation.x - startLocation.x;
      CGFloat dy = stopLocation.y - startLocation.y;
      CGFloat distance = sqrt(dx*dx + dy*dy );
      NSLog(@"Distance: %f", distance);
   }
 }

 // this  method does all other actions related to swipes

- (void)handleSwipe:(UISwipeGestureRecognizer *)gestureRecognizer
{
 UISwipeGestureRecognizerDirection direction = [gestureRecognizer direction];
     CGPoint touchLocation = [gestureRecognizer locationInView:playerLayerView];

     if (direction == UISwipeGestureRecognizerDirectionDown && touchLocation.y >  (playerLayerView.frame.size.height * .5))
     {
        if (![toolbar isHidden])
        {
           if (selectedSegmentIndex != UISegmentedControlNoSegment)
           {
              [self dismissBottomPanel];
           }
           else
           {
             [self dismissToolbar];
           }
        }
     }
 }
.

그래서 문제는 핸들이 호출되지 않는다는 것입니다 ... UIPangeStureRecognizer가 설정되면 handleswipe가 작동하기 시작합니다.

나는 제스처 인식 프로그래밍에 꽤 새로운 것이므로 여기에 기본적인 것을 놓치고 있다고 가정합니다.

모든 종류의 도움은 높이 평가됩니다!

도움이 되었습니까?

해결책

제스처를 서로 상호 작용하는 방법을 알려주는 것입니다.동시에 실행되도록 할 수 있습니다 (기본값은 그렇지 않음) 또는 다른 것들이 실패한 경우에만 하나의 작업을 설정하여 작업을 설정합니다.

두 작업을 모두 만들려면 gestures 및 gestures 및 구현

클래스를 만들고

delegate

– gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:를 반환합니다.

다른 하나가 실패한 경우에만 하나만 작동하려면 YES를 사용하십시오.

다른 팁

스 와이프 및 팬 제스처는 매우 유사하며 혼란을 일으키는

몇 가지 구제책이 있습니다 :

  1. 동일한보기에서 팬을 설정하지 마십시오. 다른 하위보기에서 혼동을 방지하기 위해 다른 하위보기에서 설정할 수 있습니다.

  2. 스 와이프 할 다른 인식기를 사용하여 두 번 탭 또는 2 개의 손가락을 탭으로 해석 할 수 없으므로

  3. 대리자 방법 사용 - GestureRecognizer : ShouldBerequiredToFailboxGestureRecognizer :

    chaco가 패널 / 도구 모음의 영역에서 시작되고 팬 인식기를 사용하여 스 와이프 할 수있는 팬 인식기를 실패합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top