我在視圖控制器的viewDidLoad方法中添加了UISwipeGestureRecognizer和UITapGestureRecognizer視圖。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