我创建了一个带有包含 ImageView 的 nib 的小型示例项目。在我的 View Controller 代码中,我在 ImageView 中添加了一个手势识别器来检测点击。但它从不调用处理程序方法。
这是标题:
#import <UIKit/UIKit.h>
@interface TapExperimentViewController : UIViewController {
UIImageView *imageView;
}
@property (retain) IBOutlet UIImageView *imageView;
- (void)handleTapUIGestureRecognizer *)sender;
@end
这是实现文件:
#import "TapExperimentViewController.h"
@implementation TapExperimentViewController
@synthesize imageView;
- (void)dealloc {
[imageView release];
[super dealloc];
}
- (void)viewDidLoad {
[super viewDidLoad];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
initWithTarget:self
actionselector(handleTap];
[self.imageView addGestureRecognizer:tap];
[tap release];
}
- (void)viewDidUnload {
[super viewDidUnload];
self.imageView = nil;
}
- (void)handleTapUIGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateEnded) {
NSLog(@"tap");
}
}
@end
我已确定 socket 已连接。为什么我触摸图像时不调用handleTap:?
Best Answer-推荐答案
我自己没有使用过手势,但我知道 UIImageView s 默认不启用用户交互。
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.
关于iphone - 为什么我的水龙头没有被识别?,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/5557411/
|