1

在我的应用程序中,我将 a添加UIImageview到 aUIViewUIButton添加到 that UIImageView。该按钮未响应触摸事件,并且未调用操作选择器。为什么?

4

4 回答 4

3

因为UIImageView它的userInteractionEnabled属性NO默认设置为。将其设置为YES

于 2012-11-20T07:37:37.597 回答
0

确保您已将 IBAction 附加到您的按钮。然后检查它是否启用了用户交互。

于 2012-11-20T07:38:48.160 回答
0
UIIMageView *image;
image.userInteractionEnabled=YES;
于 2012-11-20T10:33:24.957 回答
0

首先你添加imageview然后添加按钮然后按钮像这段代码一样正常工作

 UIView *AddView=[[UIView alloc]initWithFrame:CGRectMake(55, 0, 100, 100)];
 UIImageView *imgview=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];


                UIButton *btnRemove = [[UIButton alloc]init];
                UIImage *btnImage = [UIImage imageNamed:@"close.png"];
                [btnRemove setImage:btnImage forState:UIControlStateNormal];
                [btnRemove addTarget:self
                              action:@selector(btnREmoveAction:)
                    forControlEvents:UIControlEventTouchUpInside];
                btnRemove.frame = CGRectMake(0,0, 29, 29);

                btnRemove.tag=indexStart;

                [AddView addSubview:imgview]; // add the imageview
                [AddView addSubview:btnRemove];  // add the button 
于 2012-11-20T11:01:12.180 回答