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가 포함되어 있습니다.
탭 및 스 와이프가 인식되지 않습니다. 내가 빠진 것이 명백한가요? 감사합니다. .
이러한 방법을 호출했는지 여부를 확인 했습니까? –
'UIGestureRecognizer' 문서를 읽어주십시오. 특히 동작 메소드에서 제스처 인식기의 'state'속성을 확인하는 부분. – rmaddy
콜렉션 뷰가 전체'self.view'를 커버한다면, 콜렉션 뷰가 그것들을 모두 처리 할 것이기 때문에'self.view'에 대한 제스쳐 인식기는 결코 이벤트를 얻지 못할 것입니다. – rmaddy