0

我正在使用以下代码

@property (retain, nonatmoic) UIImageView *imgView;

  if ( count == 6)
    {
        [timer invalidate]; 
         imgView= [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,460)];

        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        {
            imgView.image = [UIImage imageNamed:@"ipad_popover-incorrectguess.png"];
            [self.view addSubview:imgView];

        }
        else if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
        {
            imgView.image = [UIImage imageNamed:@"iphone_popover-incorrectguess.png"];
            [self.view addSubview:imgView];        
        }
        UIGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
                                    initWithTarget:self action:@selector(newRound)];
        [imgView addGestureRecognizer:tap];
    }
}

-(void)newRound
{
    [imgView removeFromSuperview];
}

当我点击图像上的任何位置时,似乎从未调用过 newROUND 。

我该如何解决?

4

3 回答 3

2

您需要为 imgView 启用用户交互:

imgView.userInteractionEnabled = YES;

与 UIView 不同,UIImageView 的 userInteractionEnabled 属性默认设置为 NO,因此您需要将其显式设置为 YES 以使其接收触摸。

于 2012-09-24T15:29:13.807 回答
0

设置 tap.delegate =self。

UIGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(newRound)];

tap.delegate=自己;

[imgView addGestureRecognizer:tap];

于 2012-09-24T06:16:04.773 回答
0

此外,我会确定该类是 .h 头文件中的委托:

@interface View : UIView <UIGestureRecognizerDelegate>
于 2012-09-24T17:29:35.927 回答