0

我将 UISwipeGestureRecognizer 和 UITapGestureRecognizer 添加到视图控制器的 viewDidLoad 方法中的视图。

- (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。

点击和滑动没有被识别。我有什么明显的遗漏吗?谢谢。

4

6 回答 6

9

重新启动模拟器对我有用。

于 2015-02-17T06:57:34.270 回答
3

原来视图没有响应任何手势——滚动、点击按钮或滑动动作。~/Library/Application Support/iPhone Simulator / 6.1/Applications我从and中删除了生成的文件夹~/Library/Developer/Xcode/DerivedData,重置了模拟器设置(从iOS Simulator> Reset Contents and Settings),在 xcode 中进行了清理(Product > Clean)并再次运行了该应用程序。现在可以识别手势。我不确定以上哪一项解决了问题......可能只需重置模拟器的内容和设置就足够了。

于 2013-05-22T20:11:43.660 回答
2

您只需要选择Show Device Bezels

Goto simulator > Window > Enable Show Device Bezels

在此处输入图像描述

享受您向后滑动的手势。

于 2020-03-25T11:22:34.220 回答
0

将此方法添加到您的视图控制器,以便您的 UICollectionView 不会阻​​止其他手势

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    return true;
}
于 2013-05-22T07:47:28.160 回答
0

如果您已经从窗口面板启用了设备边框,但仍然无法使用滑动返回手势。请参考这个答案

您需要做的就是重新启动模拟器并尝试从模拟器的真实边缘滑动。

于 2020-06-22T09:00:40.977 回答
-5

首先你需要添加 UITapGestureRecognizer Delegate 方法到 .h

@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
}
于 2013-05-22T05:56:20.857 回答