Я добавляю UISwipeGestureRecognizer и UITapGestureRecognizer к представлению в режиме viewDidLoad контроллера вида.iOS Simulator Непризнанные жесты
- (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