为什么不识别我的水龙头?

时间:2011-04-05 19:31:19

标签: iphone ios uigesturerecognizer

我创建了一个带有包含图像视图的笔尖的小样本项目。在我的视图控制器代码中,我为图像视图添加了一个手势识别器来检测点击。但它从不调用处理程序方法。

这是标题:

#import <UIKit/UIKit.h>

@interface TapExperimentViewController : UIViewController {
    UIImageView *imageView;
}

@property (retain) IBOutlet UIImageView *imageView;

- (void)handleTap:(UIGestureRecognizer *)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
                                   action:@selector(handleTap:)];
    [self.imageView addGestureRecognizer:tap];
    [tap release];
}

- (void)viewDidUnload {
    [super viewDidUnload];
    self.imageView = nil;
}

- (void)handleTap:(UIGestureRecognizer *)sender {
    if (sender.state == UIGestureRecognizerStateEnded) {
        NSLog(@"tap");
    }
}

@end

我确保插座已连接好。为什么不是handleTap:当我触摸图像时被调用?

1 个答案:

答案 0 :(得分:5)

我自己没有使用过手势,但我知道UIImageView默认情况下不启用用户互动。

  

配置了新的图像视图对象   默认情况下忽略用户事件。   如果你想处理一个事件   UIImageView的自定义子类,你   必须明确改变的价值   userInteractionEnabled属性为   初始化对象后为YES。

相关问题