Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何让UIgestureRecognitors工作?_Ios_Uigesturerecognizer - Fatal编程技术网

Ios 如何让UIgestureRecognitors工作?

Ios 如何让UIgestureRecognitors工作?,ios,uigesturerecognizer,Ios,Uigesturerecognizer,我在代码中打开手势识别器时遇到问题。我在点击手势识别器中添加了一个handleTap回调,但print语句从未出现过。我只是运气不好。有人知道我做错了什么吗 在我的ViewController.h中 @interface ViewController : UIViewController<UITextFieldDelegate, UIGestureRecognizerDelegate> { } @end 编辑:我添加了一个文本字段,当我单击该文本字段时,我会看到点击选择器打印语

我在代码中打开手势识别器时遇到问题。我在点击手势识别器中添加了一个handleTap回调,但print语句从未出现过。我只是运气不好。有人知道我做错了什么吗

在我的ViewController.h中

@interface ViewController : UIViewController<UITextFieldDelegate, UIGestureRecognizerDelegate> {

}

@end

编辑:我添加了一个文本字段,当我单击该文本字段时,我会看到点击选择器打印语句。但是,如果我点击文本字段,我不会得到选择器打印语句。

我认为问题在于选择器。试着改变

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
                                   initWithTarget:self
                                   action:@selector(handleTap)];
并将其替换为

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
                                   initWithTarget:self
                                   action:@selector(handleTap:)];

使选择器与handleTap的签名匹配。

初始化时传递的选择器错误

这行应该是这样的:

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
                                       initWithTarget:self
                                       action:@selector(handleTap:)];

请注意
handleTap
之后的冒号,以匹配您要使用的方法。

显然,对UIView进行子类化并使用空函数重写drawrect导致调用选择器。

我添加了冒号,但仍然不走运。您是否检查了UIView
myView
是否位于顶部且可见?我只有一个视图,它是空的具有可见的按钮和文本字段。
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
                                       initWithTarget:self
                                       action:@selector(handleTap:)];