检查UIView是否被触摸?

时间:2010-11-21 20:57:01

标签: cocoa-touch uiview uikit uipickerview

嘿,我想能够检查用户是否触摸我的UIView所以我可以解雇我的选择器我怎么能这样做呢?谢谢!

1 个答案:

答案 0 :(得分:10)

尝试在包含UITapGestureRecognizer的{​​{1}}子类的UIView中的viewDidLoad课程中添加UIViewController。它看起来像这样:

UIView

然后实现tap的处理程序,根据上面的代码,它将如下所示:

- (void)viewDidLoad {
    [super viewDidLoad];

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self  action:@selector(viewTapped:)];
    tap.numberOfTapsRequired = 1;
    [self.aView addGestureRecognizer:tap];
    [tap release];
}

希望这有帮助,

贾斯汀