按钮没有响应触摸

时间:2012-11-20 07:35:04

标签: iphone uiimageview uibutton

在我的应用程序中,我向UIImageview添加了UIView,并向UIButton添加了UIImageView。该按钮未响应触摸事件,并且未调用操作选择器。为什么呢?

4 个答案:

答案 0 :(得分:3)

因为UIImageView默认情况下userInteractionEnabled属性设置为NO。将其设置为YES,它就会起作用。

答案 1 :(得分:0)

确保您的按钮附有IBAction。然后检查是否启用了用户交互。

答案 2 :(得分:0)

试试这个来解决它。

UIIMageView *image;
image.userInteractionEnabled=YES;

希望这有助于任何人

阿米努

答案 3 :(得分: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 
相关问题