2013-05-22 7 views
0

UISwipeGestureRecognizer 및 UITapGestureRecognizer를 뷰 컨트롤러의 viewDidLoad 메서드의 뷰에 추가합니다.iOS 시뮬레이터가 제스처를 인식하지 못합니다.

- (void)viewDidLoad { 
     [super viewDidLoad]; 
     [self.view addGestureRecognizer:[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(cardSwipe:)]]; 
     [self.view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cardTap:)]]; 
    } 
- (void)cardSwipe:(UISwipeGestureRecognizer *)sender { 
    //get the card. set faceUp to false. 
    CGPoint location = [sender locationInView:sender.view]; 
    NSIndexPath *cellIndex = [self.cardCollectionView indexPathForItemAtPoint:location]; 
    if(cellIndex){ 
     UICollectionViewCell *cell = [self collectionView:self.cardCollectionView cellForItemAtIndexPath:cellIndex]; 
     if(cell && [cell isKindOfClass:[CardCollectionViewCell class]]){ 
      [[((CardCollectionViewCell *)cell) cardView] handleCardSwipe]; 
     } 
    } 
} 
- (void)cardTap:(UITapGestureRecognizer *)sender { 
    //get the card. set faceUp to false. 
    CGPoint location = [sender locationInView:sender.view]; 
    NSIndexPath *cellIndex = [self.cardCollectionView indexPathForItemAtPoint:location]; 
    if(cellIndex){ 
     UICollectionViewCell *cell = [self collectionView:self.cardCollectionView cellForItemAtIndexPath:cellIndex]; 
     if(cell && [cell isKindOfClass:[CardCollectionViewCell class]]){ 
      [[((CardCollectionViewCell *)cell) cardView] handleCardSwipe]; 
     } 
    } 
} 

해당되는 경우 :보기에 UICollectionView가 포함되어 있습니다.

탭 및 스 와이프가 인식되지 않습니다. 내가 빠진 것이 명백한가요? 감사합니다. .

+0

이러한 방법을 호출했는지 여부를 확인 했습니까? –

+0

'UIGestureRecognizer' 문서를 읽어주십시오. 특히 동작 메소드에서 제스처 인식기의 'state'속성을 확인하는 부분. – rmaddy

+0

콜렉션 뷰가 전체'self.view'를 커버한다면, 콜렉션 뷰가 그것들을 모두 처리 할 것이기 때문에'self.view'에 대한 제스쳐 인식기는 결코 이벤트를 얻지 못할 것입니다. – rmaddy

답변

1

뷰가 아니었다 밝혀 당신의 ViewController에이 방법을 추가

@interface ViewController : UIViewController<UIGestureRecognizerDelegate> 

UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTapImgView:)]; 
     doubleTap.numberOfTapsRequired = 2; 
     doubleTap.delegate = self; 

- (void)doubleTapImgView:(UITapGestureRecognizer *)gesture 
{ 
    //Do What you want Here 
} 
+0

이것은 코드와 관련이없는 합법적 인 문제입니다. 원인에 대한 설명을 제공 할 수는 없지만. 내가 그것을 만났을 때, 내가 한 것은 시뮬레이터를 리셋하고 앱을 재배포하는 것뿐이었습니다. – Robert

+0

시뮬레이터를 재설정 한 후에이 문제가 발생하지만 iPhone 6 시뮬레이터에서만 발생합니다. – Brett

-3

먼저 당신은 당신의 UICollectionView 다른 제스처

을 차단하지 않도록
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { 
    return true; 
} 
+1

'UIGestureRecognizerDelegate'를 추가 할 필요가 없습니다. 선택 사항입니다. 델리게이트 메서드를 구현해야하는 경우에만 설정합니다. 그리고'UITapGestureRecognizerDelegate' 같은 것이 없습니다. – rmaddy

0

을있는 .h하기 UITapGestureRecognizer 위임 방법을 추가 할 필요가 스크롤링, 버튼 누르기 또는 스 와이프 동작과 같은 모든 제스처에 응답합니다. ~/Library/Application Support/iPhone Simulator/6.1/Applications~/Library/Developer/Xcode/DerivedData에서 생성 된 폴더를 삭제하고 시뮬레이터 설정 (iOS Simulator>Reset Contents and Settings)을 재설정하고 xcode (제품> 청소)를 깨끗하게 정리 한 다음 앱을 다시 실행했습니다. 이제 제스처가 인식됩니다. 위의 어느 것이 문제를 해결했는지 모르겠습니다 ... 단순히 시뮬레이터의 내용과 설정을 다시 설정하는 것으로 충분했을 것입니다.

+0

프로토콜을 컨트롤러의 인터페이스에 추가하고, self를 탭 제스처 인식기의 델리게이트로 설정하고 위의 방법을 추가했습니다. 도와주지 않았어. – septerr

2

시뮬레이터를 다시 시작하면이 효과가있었습니다.

관련 문제