iOS 模拟器无法识别手势

问题描述 投票:0回答:7

我正在将 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。

点击和滑动无法被识别。我是否缺少一些明显的东西? 谢谢。

objective-c uigesturerecognizer
7个回答
10
投票

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


3
投票

结果视图没有响应任何手势 - 滚动、点击按钮或滑动操作。我从

~/Library/Application Support/iPhone Simulator / 6.1/Applications
~/Library/Developer/Xcode/DerivedData
删除了生成的文件夹,重置模拟器设置(从
iOS Simulator
>
Reset Contents and Settings
),在 xcode 中进行清理(产品 > 清理)并再次运行应用程序。现在可以识别手势了。我不确定以上哪一项解决了问题...可能只需重置模拟器的内容和设置就足够了。


2
投票

您只需选择

Show Device Bezels
:

Goto simulator > Window > Enable Show Device Bezels

享受滑动返回手势。


0
投票

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

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    return true;
}

0
投票

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

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


0
投票

确保您按下触控板来启动手势。从 Apple 开发论坛粘贴。

这就是我在不起作用时所做的:

  • 按“选项”键
  • 看到两个圆圈
  • 前后移动鼠标

这就是我在工作时所做的事情:

  • 按“选项”键
  • 看到两个圆圈
  • 单击鼠标按钮(模拟触摸屏幕)
  • 前后移动鼠标

-5
投票

首先您需要将 UITapGestureRecognizer 委托方法添加到 .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
}
© www.soinside.com 2019 - 2024. All rights reserved.