iphone - 为什么我的水龙头没有被识别?
<p><p>我创建了一个带有包含 ImageView 的 nib 的小型示例项目。在我的 ViewController 代码中,我在 ImageView 中添加了一个手势识别器来检测点击。但它从不调用处理程序方法。</p>
<p>这是标题:</p>
<pre><code>#import <UIKit/UIKit.h>
@interface TapExperimentViewController : UIViewController {
UIImageView *imageView;
}
@property (retain) IBOutlet UIImageView *imageView;
- (void)handleTap:(UIGestureRecognizer *)sender;
@end
</code></pre>
<p>这是实现文件:</p>
<pre><code>#import "TapExperimentViewController.h"
@implementation TapExperimentViewController
@synthesize imageView;
- (void)dealloc {
;
;
}
- (void)viewDidLoad {
;
UITapGestureRecognizer *tap = [
initWithTarget:self
action:@selector(handleTap:)];
;
;
}
- (void)viewDidUnload {
;
self.imageView = nil;
}
- (void)handleTap:(UIGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateEnded) {
NSLog(@"tap");
}
}
@end
</code></pre>
<p>我已确定 socket 已连接。为什么我触摸图像时不调用handleTap:?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我自己没有使用过手势,但我知道 <a href="http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImageView_Class/Reference/Reference.html" rel="noreferrer noopener nofollow"><code>UIImageView</code></a> s 默认不启用用户交互。</p>
<blockquote>
<p>New image view objects are configured
to disregard user events by default.
If you want to handle events in a
custom subclass of UIImageView, you
must explicitly change the value of
the userInteractionEnabled property to
YES after initializing the object.</p>
</blockquote></p>
<p style="font-size: 20px;">关于iphone - 为什么我的水龙头没有被识别?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/5557411/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/5557411/
</a>
</p>
页:
[1]