0

我有一个像这样生成的视图:

oneView = [[UIView alloc] initWithFrame:CGRectMake(x, y , w, h)];
oneView.tag = i;

UITapGestureRecognizer* recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap2:)];
[recognizer setNumberOfTouchesRequired:1];
[oneView addGestureRecognizer:recognizer];
recognizer.delegate = self;
[recognizer release];

- (void)handleSingleTap2:(UITapGestureRecognizer *)recognizer {
    int viewID = recognizer.view.tag;
    NSLog(@"id : %d", viewID);
}

这可行,但如果我用 UIWebView 或 UIImageView 分配替换 UIView 分配,则不再触发触摸事件。

我怎样才能使它工作?

4

3 回答 3

0

关于你的问题,UIWebView我建议你看看drawonward的答案:

UIGestureRecognizer 是否适用于 UIWebView?

对于 UIImageView 部分,请参阅本教程:

UIImageView-with-zooming-tapping

我无法在此处粘贴代码,但我认为这将使该区域更清洁且更易于阅读。

于 2011-04-23T13:30:09.503 回答
0

你必须覆盖

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;

委托函数并返回YES;

于 2011-04-23T13:31:36.277 回答
0

设置 userInteractionEnabled=YES,如果需要,multipleTouchEnabled=YES

于 2011-04-23T13:08:12.387 回答