iOS模拟器无法识别手势

时间:2013-05-22 04:50:34

标签: objective-c uigesturerecognizer

我正在视图控制器的viewDidLoad方法中为视图添加UISwipeGestureRecognizer和UITapGestureRecognizer。

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

点击和滑动无法识别。有什么明显的东西让我失踪吗? 感谢。

6 个答案:

答案 0 :(得分:5)

重新启动模拟器为我工作。

答案 1 :(得分:2)

原来视图没有响应任何手势 - 滚动,点击按钮或滑动动作。我从~/Library/Application Support/iPhone Simulator / 6.1/Applications~/Library/Developer/Xcode/DerivedData删除了生成的文件夹,重置了模拟器设置(来自iOS Simulator> Reset Contents and Settings),在xcode(Product> Clean)中执行了清理并运行该应用程序再次。现在已经识别出手势。我不确定上述哪个问题解决了这个问题......简单地重置模拟器的内容和设置是可能的。

答案 2 :(得分:1)

您只需要选择Show Device Bezels

Goto simulator > Window > Enable Show Device Bezels

enter image description here

享受向后滑动手势。

答案 3 :(得分:0)

将此方法添加到viewcontroller,以便您的UICollectionView不会阻止其他手势

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

答案 4 :(得分:0)

如果您已经从“窗口”面板启用了“设备挡板”,但仍然无法使用滑动来返回手势。请参阅this answer

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

答案 5 :(得分:-3)

首先,您需要将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
}